LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 09-03-2009, 06:36 AM   #1
Pete-Ratcliffe
LQ Newbie
 
Registered: Sep 2009
Posts: 2

Rep: Reputation: 0
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!
 
Old 09-03-2009, 07:32 AM   #2
Berhanie
Senior Member
 
Registered: Dec 2003
Location: phnom penh
Distribution: Fedora
Posts: 1,625

Rep: Reputation: 165Reputation: 165
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
 
Old 09-03-2009, 10:55 AM   #3
Pete-Ratcliffe
LQ Newbie
 
Registered: Sep 2009
Posts: 2

Original Poster
Rep: Reputation: 0
You're absolutely correct! Thanks
 
  


Reply

Tags
bash, exit, putty


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to exit BASH with a BASH script bert07 Programming 4 09-03-2009 03:19 AM
Log what exits in bash script. What causes exit code thats not 0? Trailsmoke Programming 2 09-25-2008 04:07 AM
what is the script which runs at the exit bash shell supersubu123 Linux - General 6 01-24-2007 01:25 PM
Bash Script- command on exit PDock Programming 6 12-23-2005 08:03 PM


All times are GMT -5. The time now is 02:20 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration