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 > UNIX for Dummies Questions & Answers
.
google unix.com



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

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
what these statements means namishtiwari UNIX for Dummies Questions & Answers 1 01-17-2008 02:20 AM
Automate SQL statements panchpan SUN Solaris 3 01-03-2008 02:32 AM
Please help on IF statements. filthymonk Shell Programming and Scripting 4 07-18-2007 05:59 AM
or statements? Blip Shell Programming and Scripting 1 01-19-2004 04:08 PM
if statements lilas UNIX for Dummies Questions & Answers 2 03-22-2001 11:49 AM

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

Join Date: Nov 2006
Posts: 23
Else in If Statements

Sorry to be a pain, but how does the else work in the if statements?

Ive been making scripts with if statements but i cant get the else statements working.

Can you help?
  #2 (permalink)  
Old 11-30-2006
anbu23 anbu23 is offline Forum Advisor  
Registered User
  
 

Join Date: Mar 2006
Location: Bangalore,India
Posts: 1,398
can you show your script?
  #3 (permalink)  
Old 11-30-2006
chapmana chapmana is offline
Registered User
  
 

Join Date: Nov 2006
Posts: 23
well i haven't used the else in a script but for instance

if [ $choice = 1 ]

then

echo "cool its working"

exit 1

else

echo "not working try again"

sh andy1

fi

is this the correct way to use it
  #4 (permalink)  
Old 11-30-2006
anbu23 anbu23 is offline Forum Advisor  
Registered User
  
 

Join Date: Mar 2006
Location: Bangalore,India
Posts: 1,398
Quote:
Originally Posted by chapmana
well i haven't used the else in a script but for instance

if [ $choice = 1 ]

then

echo "cool its working"

exit 1

else

echo "not working try again"

sh andy1

fi

is this the correct way to use it
If you are comparing with numbers use -eq option
Code:
if [ $choice -eq 1 ]
Other than equal, rest is ok.
  #5 (permalink)  
Old 11-30-2006
chapmana chapmana is offline
Registered User
  
 

Join Date: Nov 2006
Posts: 23
so the eq means if its not equal to 1 then its not correct? is that right?
  #6 (permalink)  
Old 11-30-2006
anbu23 anbu23 is offline Forum Advisor  
Registered User
  
 

Join Date: Mar 2006
Location: Bangalore,India
Posts: 1,398
-eq means equal
-ne means not equal

Code:
if [ $choice -eq 1 ]
if choice is equal to one then print "cool its working" and then exit the script with one.
Closed Thread

Bookmarks

Tags
ping, ping port, port, port ping

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 07:55 PM.


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