LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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

Tags used in this thread
Popular LQ Tags , ,

Reply
 
Thread Tools
Old 09-03-2009, 06:36 AM   #1
Pete-Ratcliffe
LQ Newbie
 
Registered: Sep 2009
Posts: 2
Thanked: 0
How to exit a BASH script


[Log in to get rid of this advertisement]
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!
windows_xp_2003 Pete-Ratcliffe is offline  
Tag This Post , ,
Reply With Quote
Old 09-03-2009, 07:32 AM   #2
Berhanie
Senior Member
 
Registered: Dec 2003
Distribution: Slackware
Posts: 1,260
Thanked: 36
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
windows_vista Berhanie is offline     Reply With Quote
Thanked by:
Old 09-03-2009, 10:55 AM   #3
Pete-Ratcliffe
LQ Newbie
 
Registered: Sep 2009
Posts: 2
Thanked: 0

Original Poster
You're absolutely correct! Thanks
windows_xp_2003 Pete-Ratcliffe is offline     Reply With Quote

Reply

Bookmarks


Thread Tools

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 03:31 PM.

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
RSS2  LQ Podcast
RSS2  LQ Radio
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration