|
|||||||
| Forums | Search Forums | Register | Forum Rules | Man Pages | Albums | FAQ | Members | Calendar | Search | Today's Posts | Mark Forums Read |
| UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !! |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
multiple conditions in if/then
Hello,
I am having trouble with the syntax with a conditional statement in a BASH script involving multiple conditions. Any suggestions would be greatly appreciated! if [ "$sString" != "2" && "$sString" != "5" && "$sString" !="8 " && "$tString" !="3" && "$tString" != "5" ]; then array=("${array[@]}" "$dnNum" ) fi i receive this error: ./testscript: [: missing `]' |
| Sponsored Links | ||
|
|
#2
|
|||
|
|||
|
Did you really have this on two lines like this?
If so put a \ character right after !="8" |
| Sponsored Links | ||
|
|
#3
|
|||
|
|||
|
they are infact on the same line, but i did try adding a '\'. I also tried the if statment with only two "conditions".
i.e. f [ "$sString" != "2" && "$sString" != "5"]; then array=("${array[@]}" "$dnNum" ) fi |
|
#4
|
|||
|
|||
|
The last example is failing because of your "5" sitting next to the "]" with no whitespace. Your first example will work if you replace "&&" with "-a" or if you replace your brackets "[" and "]" with double brackets "[[" and "]]". Example: Code:
if [ "$sString" != "2" -a "$sString" != "5" ]; then ... fi and: Code:
if [[ "$sString" != "2" && "$sString" != "5" ]]; then ... fi |
| Sponsored Links | |
|
|
#5
|
|||
|
|||
|
thank you so much...this was the first time i've posted on a forum, and it def proved its usefulness...
Last edited by grandtheftander; 07-21-2006 at 02:20 PM.. |
| Sponsored Links | ||
|
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Multiple indexed conditions with ksh | vahid | Shell Programming and Scripting | 1 | 07-19-2011 10:23 PM |
| Nested if with multiple conditions | sweetnsourabh | UNIX for Dummies Questions & Answers | 3 | 11-29-2010 05:47 AM |
| specifying multiple conditions in AWK | skyineyes | Shell Programming and Scripting | 2 | 05-12-2010 10:31 AM |
| Help regarding multiple conditions | ssenthilkumar | Shell Programming and Scripting | 4 | 01-08-2010 02:10 AM |
| multiple if conditions | bashshadow1979 | Shell Programming and Scripting | 4 | 04-21-2009 03:08 PM |
|
|