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 > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
multiple conditions in if using && operator codeman007 Shell Programming and Scripting 2 12-30-2008 04:59 PM
Perl Substition with multiple conditions EDALBNUG UNIX for Dummies Questions & Answers 4 09-25-2008 03:15 PM
Multiple conditions in find or ls stmts mavsman UNIX for Dummies Questions & Answers 5 04-01-2008 04:57 PM
multiple conditions in if/then grandtheftander UNIX for Dummies Questions & Answers 4 07-21-2006 01:58 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
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 04-21-2009
bashshadow1979 bashshadow1979 is offline
Registered User
  
 

Join Date: Mar 2009
Posts: 8
multiple if conditions

Guys, Im trying to have a script that evaluates multiple conditions :

Code:
test.sh:

if [ $1 = "brazil1" ]
then
echo "host $1"
else
if [ $1 = "brazil2" ]
then
echo "host $1"
else
echo $1 not valid
exit 1
fi
when I do
Code:
 ./test.sh brazil1
I get:

Code:
./test.sh: line 12: syntax error: unexpected end of file
I'm not sure what I'm doing wrong, could you give me a hand on it please?

Thanks

Last edited by bashshadow1979; 04-21-2009 at 01:32 PM..
  #2 (permalink)  
Old 04-21-2009
giannicello giannicello is offline
Registered User
  
 

Join Date: Sep 2001
Location: Phoenix
Posts: 169
You have two 'if' and only one 'fi' if I saw this correctly. Use the code tag.
  #3 (permalink)  
Old 04-21-2009
bashshadow1979 bashshadow1979 is offline
Registered User
  
 

Join Date: Mar 2009
Posts: 8
Multiple conditions

Im sorry for not using the code tag, I will next time

What I'm trying to do is to have a script where I can send one parameter and based on that parameter execute a function.

if the script received brazil1 then echo something, if it receives brazil2 then echo something else.. etc.. etc..

Thanks guys, I'm sorry for the dumb question but I cant figure it out..
  #4 (permalink)  
Old 04-21-2009
giannicello giannicello is offline
Registered User
  
 

Join Date: Sep 2001
Location: Phoenix
Posts: 169
I don't see you put in the second 'fi' yet at the end so I'll change the second else to 'elif' for you:

Code:
if [ $1 = "brazil1" ]; then
   echo "host $1"
elif [ $1 = "brazil2" ]; then
   echo "host $1"
else
   echo $1 not valid
   exit 1
fi
  #5 (permalink)  
Old 04-21-2009
dr.house dr.house is offline
Registered User
  
 

Join Date: Dec 2008
Location: Switzerland
Posts: 221
Quote:
Originally Posted by bashshadow1979 View Post
What I'm trying to do is to have a script where I can send one parameter and based on that parameter execute a function.
I'd rather use cases, e.g.:

Code:
case $1 in
"brazil1")
  # do this
;;
"brazil2")
  # do that
;;
*)
  # oops ;-)
;;
esac
(background information)
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 08:43 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language translation by Google.
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