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
Problem with while loop in shell script rkrgarlapati Shell Programming and Scripting 20 02-02-2009 03:13 AM
Help shell script to loop through files update ctl file to be sql loaded dba_nh Shell Programming and Scripting 1 04-15-2008 09:00 PM
Infinite Loop in Autosys while running a shell script, Manual run is fine sharmagaurav_2k Shell Programming and Scripting 2 09-04-2007 09:20 AM
Shell Script loop problem MaxMouse Shell Programming and Scripting 1 07-26-2005 04:19 PM
shell script - loop to countdown froggwife UNIX for Dummies Questions & Answers 2 11-29-2001 10:48 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 07-31-2006
pankajkrmishra pankajkrmishra is offline
Registered User
  
 

Join Date: Jul 2006
Posts: 55
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
  #2 (permalink)  
Old 07-31-2006
aigles's Avatar
aigles aigles is offline Forum Advisor  
Registered User
  
 

Join Date: Apr 2004
Location: Bordeaux, France
Posts: 1,423
Missing space betwen Bangalore and ]


Jean-Pierre.
  #3 (permalink)  
Old 07-31-2006
pankajkrmishra pankajkrmishra is offline
Registered User
  
 

Join Date: Jul 2006
Posts: 55
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 (permalink)  
Old 07-31-2006
vino's Avatar
vino vino is offline Forum Staff  
Supporter (in vino veritas)
  
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,798
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
  #5 (permalink)  
Old 07-31-2006
pankajkrmishra pankajkrmishra is offline
Registered User
  
 

Join Date: Jul 2006
Posts: 55
Thanks a lot........ Its working now

Regards

Pankaj
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:12 AM.


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