Unix/Linux Go Back    


Shell Programming and Scripting BSD, Linux, and UNIX shell scripting Post awk, bash, csh, ksh, perl, php, python, sed, sh, shell scripts, and other shell scripting languages questions here.

exit a shell script!!

Shell Programming and Scripting


Closed    
 
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: 7 November 2016, 6:31 AM EST
Location: Bangalore,India
Posts: 2,152
Thanks: 21
Thanked 159 Times in 150 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: 3 August 2015, 2:59 PM 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 Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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



All times are GMT -4. The time now is 09:53 PM.