batty batty - 2 years ago 108
Bash Question

Find substring in shell script variable

I have a string


in my shell script code. I need a conditional statement to check if
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 Source

What shell? Using bash:

if [[ "$VAR" =~ "UAT" ]]; then
    echo "matched"
    echo "didn't match"
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download