IF THEN ELIF question in BOURNE SHELL | Unix Linux Forums | UNIX for Dummies Questions & Answers

  Go Back    


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

IF THEN ELIF question in BOURNE SHELL

UNIX for Dummies Questions & Answers


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 04-20-2007
arun_st arun_st is offline
Registered User
 
Join Date: Mar 2007
Last Activity: 26 April 2007, 10:40 AM EDT
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
IF THEN ELIF question in BOURNE SHELL

Hi,

I get an error when executing this sample script.

#!bin/sh
if [ $1 = ];
then
echo "you need to enter the release as the first parameter"
elif [ $1 = "ALL" ];
then
echo "HI how are you ABC"
echo "Hi how are you XYZ"
echo " hi how are you all"
else
echo "using the $1 as input parameter"
fi

i get the following error.
[: arun.sh 5: FSUM6807 expression syntax error

the script requires a parameter to be passed.. If no parameter is passed the script works fine and it displays the right message. and if the parameter is ALL then also it works fine...i get the above error only if the parameter is other than null or ALL.. how to resolve this...looks like there is a problem with the else statement.
Sponsored Links
    #2  
Old 04-20-2007
anbu23's Avatar
anbu23 anbu23 is offline Forum Advisor  
Advisor
 
Join Date: Mar 2006
Last Activity: 21 November 2014, 4:45 AM EST
Location: Bangalore,India
Posts: 2,091
Thanks: 12
Thanked 131 Times in 126 Posts
Change
Code:
if [ $1 = ];

to
Code:
if [ -z $1 ];

Sponsored Links
    #3  
Old 04-20-2007
johnf johnf is offline
Registered User
 
Join Date: May 2006
Last Activity: 10 April 2014, 6:14 AM EDT
Location: England
Posts: 406
Thanks: 7
Thanked 7 Times in 7 Posts
Quote:
Originally Posted by anbu23
Change
Code:
if [ $1 = ];

to
Code:
if [ -z $1 ];

if [ $1 = "" ];
    #4  
Old 04-20-2007
reborg's Avatar
reborg reborg is offline Forum Advisor  
Administrator Emeritus
 
Join Date: Mar 2005
Last Activity: 29 March 2012, 7:00 PM EDT
Location: Ireland
Posts: 4,464
Thanks: 0
Thanked 11 Times in 11 Posts
Don't forget to quote the variable with -z, otherwise an unset variable will break the script.


Code:
if [ -z "$1" ];

Sponsored Links
    #5  
Old 04-20-2007
arun_st arun_st is offline
Registered User
 
Join Date: Mar 2007
Last Activity: 26 April 2007, 10:40 AM EDT
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
It worked

Hi

I tried ur suggetion and it worked. Thanks a lot
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
How to activate Korn Shell functionnalities in Bourne Shell madmat Shell Programming and Scripting 3 03-31-2010 09:41 AM
I need to understand the differences between the bash shell and the Bourne shell awk_sed_hello Shell Programming and Scripting 7 11-05-2009 05:40 AM
simple shell script with elif and for nexxt locutus01 Shell Programming and Scripting 2 10-06-2009 07:08 AM
Bourne Shell: if elsif question leostar_10 Shell Programming and Scripting 3 03-09-2008 08:37 PM
bourne shell timing question gillbates UNIX for Dummies Questions & Answers 7 02-01-2004 04:44 PM



All times are GMT -4. The time now is 06:58 AM.