Hi all, I'm confused about the proper syntax for multi-conditional if then statements. I'm trying to set limitations on info input on the command line.. i.e.
if [$x=[+|-|/|*|%]] ;then
$x=$vr1
else
print "You have entered an invalid option."
Can someone please clue me in on what is wrong with my syntax; what teh correct syntax is for using "and" "or" in similar statements.
On assignments to a variable, do x= instead of $x= .
When you use a mixture of -o and -a, you might have to control precedence. In the following, the first line would test true because -o has precedence:
if [ a = a -o b = b -a c = C ]
But add parentheses (you would need to backslash these) and it would now test false:
if [ ( a = a -o b = b ) -a c = C ]
Also, when checking for several values, a case statement makes for nice clean code, and even more handy when each value will result in a different action:
case $x in
+|-|/|%) x=$vr1;;
*) print "You have entered an invalid option."
exit 1;;
esac