exit a 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.

exit a shell script!!

Shell Programming and Scripting


Closed Linux or Unix Question    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 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 Unix and Linux 03-27-2007
anbu23's Unix or Linux Image
anbu23 anbu23 is offline Forum Advisor  
Advisor
 
Join Date: Mar 2006
Last Activity: 16 March 2015, 4:56 AM EDT
Location: Bangalore,India
Posts: 2,136
Thanks: 14
Thanked 150 Times in 143 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 Unix and Linux 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 Unix and Linux 03-27-2007
dennis.jacob's Unix or Linux Image
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 Unix and Linux 03-27-2007
Dhruva's Unix or Linux Image
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 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
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 05:20 AM.