exit a shell script!! | Unix Linux Forums | Shell Programming and Scripting

  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.

exit a shell script!!

Shell Programming and Scripting


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 03-27-2007
sami98 sami98 is offline
Registered User
 
Join Date: Mar 2007
Last Activity: 17 February 2008, 9:41 AM EST
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
exit a shell script!!

could somebody tell me please how to exit a shell script:

if [ $# -eq 0 ]
then
echo "No arguments detected"
exit 1
fi
...
echo "still there" # is displayed .. :-(
Sponsored Links
    #2  
Old 03-27-2007
anbu23's Avatar
anbu23 anbu23 is offline Forum Advisor  
Advisor
 
Join Date: Mar 2006
Last Activity: 8 October 2014, 1:35 AM EDT
Location: Bangalore,India
Posts: 2,089
Thanks: 12
Thanked 131 Times in 126 Posts

Code:
if [ $# -eq 0 ]
then
echo "No arguments detected"
exit 1 #exit shell script  
fi
...
echo "still there" # is displayed .. :-(

Sponsored Links
    #3  
Old 03-27-2007
sami98 sami98 is offline
Registered User
 
Join Date: Mar 2007
Last Activity: 17 February 2008, 9:41 AM EST
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
sorry...... I have the following situation and it does not work :-( :

if [ $# -eq 0 ]
then
usage()
fi

echo "still there.."

usage {
echo "No arguments detected"
exit 1 #exit shell script
}
    #4  
Old 03-27-2007
dennis.jacob's Avatar
dennis.jacob dennis.jacob is offline Forum Advisor  
Registered User
 
Join Date: Feb 2007
Last Activity: 30 March 2014, 9:33 AM EDT
Location: Singapore/Cochin
Posts: 871
Thanks: 0
Thanked 12 Times in 11 Posts
Try this..


Code:
function  usage {
echo "No arguments detected"
exit 1 #exit shell script
}
if [ $# -eq 0 ]
then
usage
fi

echo "still there.."

Sponsored Links
    #5  
Old 03-27-2007
Dhruva's Avatar
Dhruva Dhruva is offline
Registered User
 
Join Date: Mar 2006
Last Activity: 2 November 2012, 12:45 AM EDT
Location: India
Posts: 255
Thanks: 0
Thanked 1 Time in 1 Post
Function must be declared before it is used in script.try the below script..

Code:
usage ()
{
echo "No arguments detected"
exit 1 #exit shell script
}

if [ $# -eq 0 ];
then
usage
fi

echo "still there.."

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
exit shell from a script kopper Shell Programming and Scripting 1 09-09-2010 09:25 PM
how to exit out of the calling Shell Script harimac Shell Programming and Scripting 7 08-19-2009 03:20 PM
Normal exit from shell script 1manraj1 Shell Programming and Scripting 1 04-22-2009 03:37 AM
unable to exit from a shell script Sreejith_VK Shell Programming and Scripting 2 05-30-2008 03:29 AM
using exit command in a shell script jpprial UNIX for Dummies Questions & Answers 1 02-16-2001 11:45 AM



All times are GMT -4. The time now is 03:41 AM.