LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices

Reply
 
Search this Thread
Old 01-23-2013, 01:50 PM   #1
Xyaib
LQ Newbie
 
Registered: Jan 2013
Posts: 1

Rep: Reputation: Disabled
BASH scripting Condition Statements


Hello, my code looks as follows:

Code:
if [ "$state" = 1 ] && [ "$i" = *1* ] && [ "$i" != *Batch* ] && [ "$i" != *Int* ]; then 

   echo "--------------------------------"
However it yells at me because I have more then 2 conditions.

Is there a way to force it to accept 4-6 conditions?

Thanks
 
Old 01-23-2013, 02:18 PM   #2
dru8274
Member
 
Registered: Oct 2011
Location: New Zealand
Distribution: Debian
Posts: 105

Rep: Reputation: 36
Quote:
Originally Posted by Xyaib View Post
Code:
if [ "$state" = 1 ] && [ "$i" = *1* ] && [ "$i" != *Batch* ] && [ "$i" != *Int* ]; then 
   echo "--------------------------------"
fi
I see two problems here. First, you have used "=" (used for variable assignment) when you need to use "==" (used for equality in a test statement). Second, bash has a preferred double-bracket syntax for test-conditions - it allows you to move the "&&" inside, as described here.
Code:
if [[ "$state" == 1  && "$i" == *1* && "$i" != *Batch* && "$i" != *Int* ]] ; then
   echo "--------------------------------"
fi
Happy with ur solution... then tick "yes" and mark as Solved!

Last edited by dru8274; 01-23-2013 at 02:45 PM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
BASH How while loops handle multiple if statements? DevonB Linux - Newbie 3 12-28-2009 06:13 AM
bash scripting problem with nested if statements in while loop error xskycamefalling Programming 4 05-11-2009 03:14 PM
[bash] if statements in a loop MarkGM Programming 3 04-02-2009 08:12 PM
BASH IF statements Part II kinetik Programming 4 05-07-2006 01:18 AM
Newbie troubles with Bash if/then statements jimieee Programming 4 12-04-2003 06:33 PM


All times are GMT -5. The time now is 02:13 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration