The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com



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

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
problem with if, while, for conditions kittusri9 Shell Programming and Scripting 3 04-24-2008 09:15 AM
Multiple conditions in find or ls stmts mavsman UNIX for Dummies Questions & Answers 5 04-01-2008 04:57 PM
if statement with two conditions cin2000 Shell Programming and Scripting 1 01-23-2006 03:21 PM
if statement with two conditions -e, && yongho Shell Programming and Scripting 16 06-14-2005 04:46 PM
multiple conditions in if statements tim mauger Shell Programming and Scripting 3 04-28-2002 09:42 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 07-21-2006
grandtheftander grandtheftander is offline
Registered User
  
 

Join Date: Jul 2006
Posts: 8
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 `]'
  #2 (permalink)  
Old 07-21-2006
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,715
Did you really have this on two lines like this?
If so put a \ character right after !="8"
  #3 (permalink)  
Old 07-21-2006
grandtheftander grandtheftander is offline
Registered User
  
 

Join Date: Jul 2006
Posts: 8
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 (permalink)  
Old 07-21-2006
tmarikle tmarikle is offline Forum Advisor  
Registered User
  
 

Join Date: Jan 2005
Posts: 683
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
  #5 (permalink)  
Old 07-21-2006
grandtheftander grandtheftander is offline
Registered User
  
 

Join Date: Jul 2006
Posts: 8
Talking

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

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 11:36 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0