If then else loop in Shell script | Unix Linux Forums | Shell Programming and Scripting

  Unix/Linux Go Back    


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

If then else loop in Shell script

Shell Programming and Scripting


Closed Linux or Unix Question    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 07-31-2006
pankajkrmishra pankajkrmishra is offline
Registered User
 
Join Date: Jul 2006
Last Activity: 18 January 2007, 10:29 AM EST
Posts: 55
Thanks: 0
Thanked 0 Times in 0 Posts
If then else loop in Shell script

Hi

Following is the code . When I give input as Bangalore,its dospalying Welcome to Hitech City. But say , if I select Delhi or US, its not displaying the corresponding message. Its still says Welcome to Hitech City.

Seems that it not entering in the elif part. Please suggest.

#! bin/bash
echo "Enter the name of City from following :Bangalore,Delh,US"
read dist
if [ $dist=Bangalore]
then
echo " Welcome to Hitech City"
elif [ $dist=Delhi ]
then
echo " Welcome to National Capital "
elif [ $dist=US ]
then
tput blink
echo " Well you are trying for US !!! "
else
echo " Please try again from given option only !!!! "
fi

Thanks
Pankaj
Sponsored Links
    #2  
Old Unix and Linux 07-31-2006
aigles's Unix or Linux Image
aigles aigles is offline Forum Advisor  
Registered User
 
Join Date: Apr 2004
Last Activity: 1 December 2014, 9:03 AM EST
Location: Bordeaux, France
Posts: 1,711
Thanks: 2
Thanked 61 Times in 57 Posts
Missing space betwen Bangalore and ]


Jean-Pierre.
Sponsored Links
    #3  
Old Unix and Linux 07-31-2006
pankajkrmishra pankajkrmishra is offline
Registered User
 
Join Date: Jul 2006
Last Activity: 18 January 2007, 10:29 AM EST
Posts: 55
Thanks: 0
Thanked 0 Times in 0 Posts
Hey

Tried with your suggestion too.... Hard Luck ....... Same problem.... Its not entering other elif condition

I think there is some problem with read command . I m nt sure

bye
Pankaj
    #4  
Old Unix and Linux 07-31-2006
vino's Unix or Linux Image
vino vino is offline Forum Advisor  
Supporter (in vino veritas)
 
Join Date: Feb 2005
Last Activity: 12 March 2015, 5:33 AM EDT
Location: Sydney, Down Under
Posts: 2,848
Thanks: 0
Thanked 13 Times in 13 Posts
Introduce a whitespace on either side of =


Code:
#! bin/bash
echo "Enter the name of City from following :Bangalore,Delh,US"
read dist
if [ $dist = Bangalore ]
then
echo " Welcome to Hitech City"
elif [ $dist = Delhi ]
then
echo " Welcome to National Capital "
elif [ $dist = US ]
then
tput blink
echo " Well you are trying for US !!! "
else
echo " Please try again from given option only !!!! "
fi

Sponsored Links
    #5  
Old Unix and Linux 07-31-2006
pankajkrmishra pankajkrmishra is offline
Registered User
 
Join Date: Jul 2006
Last Activity: 18 January 2007, 10:29 AM EST
Posts: 55
Thanks: 0
Thanked 0 Times in 0 Posts
Thanks a lot........ Its working now

Regards

Pankaj
Sponsored Links
Closed Linux or Unix Question

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Unix or Linux Image More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Avoiding For Loop in Shell Script hydrabane Shell Programming and Scripting 6 08-19-2011 12:08 PM
Shell script using loop alisha Shell Programming and Scripting 23 07-20-2010 05:39 AM
Loop in shell script vin_pll Shell Programming and Scripting 3 11-17-2009 03:44 AM
Help with loop in a shell script elifchen Shell Programming and Scripting 2 09-24-2009 09:48 AM
how to call shell script from pl/sql loop rosalinda Shell Programming and Scripting 1 08-22-2008 07:26 AM



All times are GMT -4. The time now is 01:50 AM.