How would I construct a (possibly simple) IF statement?

Hi all,

I thought this would be simple, but I've been having a lot of trouble trying to write this IF statement, if I may ask for help pls:

In BASH, how would I construct the if statement:
Should ONLY be true if

[[USEROPTscript=="yes"]] AND [[ $mode=="INSTALL" /or/ $mode=="CHANGE" ]]

...the closest I can get is a variant where it runs, but it incorrectly thinks it's true if $mode=="REMOVE"

Thanks so much,
JMC

Please show us the actual code that you have written (including how mode and USEROPTscript are being set and any diagnostic messages produced when you run your script). And, please use CODE tags when displaying your code and any output your code produces.

Please, try any of these, in bash:

[[ $USEROPTscript = yes  &&  ($mode = INSTALL || $mode = CHANGE) ]] && echo "True" || echo "False"

Or

[[ $USEROPTscript = yes && $mode =~ ^(INSTALL|CHANGE)$ ]] && echo "True" || echo "False"

Equivalent to:

if [[ $USEROPTscript = yes && $mode =~ ^(INSTALL|CHANGE)$ ]]; then
    echo "True"
else
    echo "False"
fi

Note: watch for the proper spaces between [[ and ]] . Watch the $ sign for variables. These suggestions are given on the fly, without testing.

1 Like

Thank you so much, Aia!! This worked beautifully!!

-jmc