Visit the LQ Articles and Editorials section
Go Back > Forums > Non-*NIX Forums > Programming
User Name
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.


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

Rep: Reputation: 0
How to exit a BASH script


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:

if [ ! -e ] ; then
echo "Unable to find!"
echo ""
read prompt?'Please create before continuing. Press any key to continue . . .'
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, 06:32 AM   #2
Senior Member
Registered: Dec 2003
Location: phnom penh
Distribution: Fedora
Posts: 1,625

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

# sourcing:
. ./

# executing
Old 09-03-2009, 09:55 AM   #3
LQ Newbie
Registered: Sep 2009
Posts: 2

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


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 02:19 AM
Log what exits in bash script. What causes exit code thats not 0? Trailsmoke Programming 2 09-25-2008 03:07 AM
what is the script which runs at the exit bash shell supersubu123 Linux - General 6 01-24-2007 12:25 PM
Bash Script- command on exit PDock Programming 6 12-23-2005 07:03 PM

All times are GMT -5. The time now is 10:50 PM.

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