![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | 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 here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| IF THEN ELIF question in BOURNE SHELL | arun_st | UNIX for Dummies Questions & Answers | 4 | 04-20-2007 09:41 AM |
| Bourne-again shell | mrsamer | UNIX for Dummies Questions & Answers | 3 | 09-29-2006 11:42 PM |
| bourne shell not working | gillbates | Shell Programming and Scripting | 6 | 06-17-2004 01:22 PM |
| bourne shell timing question | gillbates | UNIX for Dummies Questions & Answers | 7 | 02-01-2004 01:44 PM |
| bourne shell script | psrinivas | Shell Programming and Scripting | 2 | 12-06-2001 12:38 PM |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Bourne Shell: if elsif question
Hi All,
Must be something obvious I am missing, but the simple script below doesn't work. #!/bin/sh x=4 if [ "$x" -eq "4" ] then echo "x is $x" elsif [ "$x" -gt "4" ] then echo "x is greater than 4" else echo "x is less than 4" fi When I run this script, I get the error message: 7: Syntax error "then" unexpected (expecting "fi") Please Help. Thanks in Advance. |
| Forum Sponsor | ||
|
|
|
#2
|
|||
|
|||
|
ok, for one you dont need all those quotes in the if statement. and i do believe your elsif is supposed to be spelled elif.. maybe that will help?
|
|
#3
|
|||
|
|||
|
This should work for you
Code:
#!/bin/sh x=4 if [ "$x" -eq "4" ] then echo "x is $x" elif [ "$x" -gt "4" ] then echo "x is greater than 4" else echo "x is less than 4" fi |
|
#4
|
|||
|
|||
|
Thanks. That was it. Strange that the website from where I am learning shell scripting has it elsif everywhere..hmm.
|
|||
| Google The UNIX and Linux Forums |