Sponsored Content
Top Forums Shell Programming and Scripting how to exit out of the calling Shell Script Post 302345245 by harimac on Tuesday 18th of August 2009 06:02:32 PM
Old 08-18-2009
how to exit out of the calling Shell Script

Hi All,

I tried looking for this, but was not able to get a clear answer. Hence posting here. Please find the details below. Thanks for the help

I have 2 shell scripts, script1.sh and script2.sh. I call script2.sh from within script1.sh ( by simple ./script2.sh command).

Based on some condition, i use exit 0 to exit out of script2.sh. I was trying to find if i can exit out of script1.sh as well at once.

Can anyone please clarify, if there is a way to do that.

below is the example

script1.sh
Code:
#!/bin/bash

echo "Before ..."
./script2.sh
echo "After ..."


script2.sh
Code:
#!/bin/bash

# check if a file exists and is not empty, if not empty exit (but i want to  exit out of script1 as well )

if [[ -s err.log ]]; then
     echo " There was problem file is empty "
     cat err.log
     echo " The Script will Exit. Please fix the issue and run again..."
     exit 0
  else
     echo " file is Empty. Proceeding with the next step... "
   fi



----
When i execute below is the output

Before ...
There was problem file is empty
The Script will Exit. Please fix the issue and run again...
After ...

I am trying to exit out of script1.sh as well so that i dont print "After ..."

thanks for the help

edit by bakunin: added code-tags. As this is your first post i will not charge you the usual rate (many, many bits, which will make me stinking rich) out of charity. Still, i would like to see you use them yourself in the future instead of relying on me to provide them afterwards. Thanks for your consideration.

Last edited by bakunin; 08-18-2009 at 07:50 PM..
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Calling shell script ?

hi friends, i'm new to unix and straight away i had to start with the script files. I've a script file which gets called from a menu item on a GUI. This script file again calls .awk file, in performing some tasks , which also generates certain files. I modified the files to generate some... (1 Reply)
Discussion started by: Ravi_Kandula
1 Replies

2. Shell Programming and Scripting

Passing exit code to calling script

In production I need to pass an exit code from a script that is being called 3 or 4 layers deep. I've created test scripts to play with it until I get it right. As you can tell, this is not my normal job. Perhaps I should have entered this in UNIX for Dummies section. Anyway, I keep losing the... (2 Replies)
Discussion started by: debbiekuch
2 Replies

3. Shell Programming and Scripting

exit a shell script!!

could somebody tell me please how to exit a shell script: if then echo "No arguments detected" exit 1 fi ... echo "still there" # is displayed .. :-( (4 Replies)
Discussion started by: sami98
4 Replies

4. Shell Programming and Scripting

Calling Shell Script

Hello Friends, I have bash script on unix server which i want to call from windows server. Basically i want a command line which will call this script on unix server. Any one has any idea regarding this? Help really appreciated!! Thanks, Roshni. (1 Reply)
Discussion started by: onlyroshni
1 Replies

5. Shell Programming and Scripting

Calling shell functions from another shell script

Hi, I have a query .. i have 2 scripts say 1.sh and 2.sh 1.sh contains many functions written using shell scripts. 2.sh is a script which needs to call the functions definded in 1.sh function calls are with arguments. Can some one tell me how to call the functions from 2.sh? Thanks in... (6 Replies)
Discussion started by: jisha
6 Replies

6. Shell Programming and Scripting

Calling another shell script

Hi there, I have an script reading content of a file and runs whatever command is specified there, as follows #!/bin/bash # Supposed to read from a file that commands are listed to be run # when the server starts for initialization CMD_FILE=/myScripts/startup/task2do.txt if ; then ... (2 Replies)
Discussion started by: james gordon
2 Replies

7. Shell Programming and Scripting

calling 'n' number of shell scripts based on dependency in one shell script.

Hello gurus, I have three korn shell script 3.1, 3.2, 3.3. I would like to call three shell script in one shell script. i m looking for something like this call 3.1; If 3.1 = "complete" then call 3.2; if 3.2 = ''COMPlete" then call 3.3; else exit The... (1 Reply)
Discussion started by: shashi369
1 Replies

8. Shell Programming and Scripting

exit shell from a script

hi guys I have a script that I need to terminate or exit the shell or session completely for the user but the exit only exit from the script and takes the user to the shell I found this https://www.unix.com/unix-dummies-questions-answers/399-using-exit-command-shell-script.html saying that... (1 Reply)
Discussion started by: kopper
1 Replies

9. Programming

Gcc error when calling exit(-1) in a .c file

gcc is giving me an error when calling exit(-1) in xbuplot.c cd ../pltlib; make xbuplot.o make: Entering directory `/media/ios120/chrisd/research/fast-zb/fast/pltlib' gcc -c -o xbuplot.o xbuplot.c xbuplot.c: In function ‘xbuinit_': xbuplot.c:171:5: warning: incompatible implicit... (5 Replies)
Discussion started by: kristinu
5 Replies

10. Shell Programming and Scripting

Exit the shell script

Hi, suppose my script is sample.sh i have to run using '. ./sample.sh' as . ./script file always executes the script in my parent shell. when my sample.sh contains exit command .. my environment is getting closed as am executing in the parent shell ... please suggest me how can i use... (5 Replies)
Discussion started by: pracheth
5 Replies
SHELL-QUOTE(1)						User Contributed Perl Documentation					    SHELL-QUOTE(1)

NAME
shell-quote - quote arguments for safe use, unmodified in a shell command SYNOPSIS
shell-quote [switch]... arg... DESCRIPTION
shell-quote lets you pass arbitrary strings through the shell so that they won't be changed by the shell. This lets you process commands or files with embedded white space or shell globbing characters safely. Here are a few examples. EXAMPLES
ssh preserving args When running a remote command with ssh, ssh doesn't preserve the separate arguments it receives. It just joins them with spaces and passes them to "$SHELL -c". This doesn't work as intended: ssh host touch 'hi there' # fails It creates 2 files, hi and there. Instead, do this: cmd=`shell-quote touch 'hi there'` ssh host "$cmd" This gives you just 1 file, hi there. process find output It's not ordinarily possible to process an arbitrary list of files output by find with a shell script. Anything you put in $IFS to split up the output could legitimately be in a file's name. Here's how you can do it using shell-quote: eval set -- `find -type f -print0 | xargs -0 shell-quote --` debug shell scripts shell-quote is better than echo for debugging shell scripts. debug() { [ -z "$debug" ] || shell-quote "debug:" "$@" } With echo you can't tell the difference between "debug 'foo bar'" and "debug foo bar", but with shell-quote you can. save a command for later shell-quote can be used to build up a shell command to run later. Say you want the user to be able to give you switches for a command you're going to run. If you don't want the switches to be re-evaluated by the shell (which is usually a good idea, else there are things the user can't pass through), you can do something like this: user_switches= while [ $# != 0 ] do case x$1 in x--pass-through) [ $# -gt 1 ] || die "need an argument for $1" user_switches="$user_switches "`shell-quote -- "$2"` shift;; # process other switches esac shift done # later eval "shell-quote some-command $user_switches my args" OPTIONS
--debug Turn debugging on. --help Show the usage message and die. --version Show the version number and exit. AVAILABILITY
The code is licensed under the GNU GPL. Check http://www.argon.org/~roderick/ or CPAN for updated versions. AUTHOR
Roderick Schertler <roderick@argon.org> perl v5.16.3 2010-06-11 SHELL-QUOTE(1)
All times are GMT -4. The time now is 01:19 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy