Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers


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 !!

Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 07-21-2006
Registered User
 
Join Date: Jul 2006
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
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  
Old 07-21-2006
...@...
 
Join Date: Feb 2004
Location: NM
Posts: 9,654
Thanks: 164
Thanked 645 Times in 622 Posts
Did you really have this on two lines like this?
If so put a \ character right after !="8"
Sponsored Links
    #3  
Old 07-21-2006
Registered User
 
Join Date: Jul 2006
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
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  
Old 07-21-2006
Registered User
 
Join Date: Jan 2005
Posts: 683
Thanks: 0
Thanked 4 Times in 4 Posts
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  
Old 07-21-2006
Registered User
 
Join Date: Jul 2006
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Computer

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
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
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



All times are GMT -4. The time now is 08:13 AM.