how to exit out of the calling Shell Script
Hi All,
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 #!/bin/bash echo "Before ..." ./script2.sh echo "After ..." script2.sh #!/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 |
script1.sh
Code:
#!/bin/bash |
A little add-on to the catkin's solution: script2.sh should return a status code different from 0, otherwise script1.sh will receive a "success" status:
Code:
exit 1 Code:
kill -9 $PPID |
Quote:
|
All times are GMT -5. The time now is 06:32 AM. |