![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| How to giv two conditions in IF statement..?? | RRVARMA | Shell Programming and Scripting | 6 | 04-25-2008 09:33 AM |
| Multiple conditions in find or ls stmts | mavsman | UNIX for Dummies Questions & Answers | 5 | 04-01-2008 04:57 PM |
| How to write multiple echo statements in unix? | Shrutiduggal | Shell Programming and Scripting | 2 | 01-09-2007 04:27 AM |
| multiple conditions in if/then | grandtheftander | UNIX for Dummies Questions & Answers | 4 | 07-21-2006 01:58 PM |
| if statement with two conditions | cin2000 | Shell Programming and Scripting | 1 | 01-23-2006 03:21 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
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: Code:
case $x in
+|-|/|%) x=$vr1;;
*) print "You have entered an invalid option."
exit 1;;
esac
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|