Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm using set -e to force my script to exit whenever an error occurs running a command. However this has the side effect of closing my putty terminal window that I am using to connect via SSH to the host.

How do I stop the terminal from closing?

share|improve this question
up vote 9 down vote accepted

How are you running the script? The circumstances of a subprocess's exit shouldn't affect the shell that ran it... unless you're sourcing the script into your running shell.

For example...

./ # this should terminate and leave your shell intact
. # this might terminate and take your shell with it

A 'nix shell is a running process of some shell interpreter (e.g., bash, ksh, csh). "source"ing a script (which you can do in bash with the command source or its alias .) tells that interpreter to open the indicated file and process its contents. In effect, the script becomes a shortcut for entering commands interactively. Functions defined, variables set, and (in your case) exits processed take effect in the original shell.

./ is a simple file path. ./ refers to the current directory and to a script within that directory. When the file is marked as executable, the file will be executed. In the case of a script, this means launching a new interpreter process (as defined by the #! line at the top of the script, or /bin/sh by default) and using it to interpret the script. Functions defined, variables set, and exits processed are confined to that new interpreter process.

share|improve this answer
You are right I am using ". my-script". Can you explain the difference please? – DD. Jul 9 '12 at 6:59
To put it inelegantly, "./" means "run the program ./" as a new process. "." means "make this script part of my current process". – Jenny D Jul 9 '12 at 7:04
I edited my answer to add further explanation, as requested. – anderbubble Jul 9 '12 at 7:39
Man, I cannot believe all this time I was reconnecting, logging in, setting up environment and executing because of this minor quirk! lol! – Michal Ciechan 1 hour ago

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.