batty batty - 7 months ago 13
Bash Question

Find substring in shell script variable

I have a string

$VAR="I-UAT";


in my shell script code. I need a conditional statement to check if
"UAT"
is present in that string.

What command should I use to get either true or false boolean as output?
Or is there any other way of checking it?

Answer

What shell? Using bash:

if [[ "$VAR" =~ "UAT" ]]; then
    echo "matched"
else
    echo "didn't match"
fi