Welcome to the most active Linux Forum on the web.
Go Back > Forums > Linux Forums > Linux - General
User Name
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.


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

Rep: Reputation: Disabled
BASH scripting Condition Statements

Hello, my code looks as follows:

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?

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

Rep: Reputation: 37
Originally Posted by Xyaib View Post
if [ "$state" = 1 ] && [ "$i" = *1* ] && [ "$i" != *Batch* ] && [ "$i" != *Int* ]; then 
   echo "--------------------------------"
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.
if [[ "$state" == 1  && "$i" == *1* && "$i" != *Batch* && "$i" != *Int* ]] ; then
   echo "--------------------------------"
Happy with ur solution... then tick "yes" and mark as Solved!

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


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 > Forums > Linux Forums > Linux - General

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

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