LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   How to exit a BASH script (https://www.linuxquestions.org/questions/programming-9/how-to-exit-a-bash-script-752347/)

Pete-Ratcliffe 09-03-2009 05:36 AM

How to exit a BASH script
 
Greetings,

I have a script that checks for the existence of a file and, if this file doesn't exist, I want the script to output a message to the screen then terminate.

This is all fairly simple and I've got a solution that works, only problem is, when the script terminates, it closes my PuTTY session!

Below is the code I'm using:

Quote:

if [ ! -e _Settings.sh ] ; then
echo "Unable to find _Settings.sh!"
echo ""
read prompt?'Please create _Settings.sh before continuing. Press any key to continue . . .'
exit
fi
Is there an alternative to 'exit' so my session can remain open? I know I could expand the if clause with an else but that just seems a bit overkill imo.

Thanks in advance!

Berhanie 09-03-2009 06:32 AM

Quote:

only problem is, when the script terminates, it closes my PuTTY session!
Sounds like you're sourcing the file, instead of just executing it.

Code:

# sourcing:
. ./script.sh

# executing
./script.sh


Pete-Ratcliffe 09-03-2009 09:55 AM

You're absolutely correct! Thanks


All times are GMT -5. The time now is 05:57 AM.