Super User is a question and answer site for computer enthusiasts and power users. 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 am using CentOS 5.4. I created a bash script that does some checking before running any commands. If the check fails, it will simply exit 0. The problem I am having is that on our server, the script will exit the su or ssh session when the exit 0 is called.

# check if directory has contents and exit if none
if [ -z "`ls /ebs_raid/import/*.txt 2>/dev/null`" ]; then
  echo "ok"
  exit 0

here is the output:

[root@ip-10-251-86-31 ebs_raid]# . 
[russ@ip-10-251-86-31 ebs_raid]$

as you can see, I was removed from my sudo session, if I wasn't in the sudo session, it would have logged me out of my ssh session. I am not sure what I am doing wrong here or where to start.

share|improve this question
You can do this, by the way: if ! ls /ebs_raid/import/*.txt 2>/dev/null; then – Dennis Williamson Apr 23 '10 at 23:14
up vote 3 down vote accepted

When you use . to run a shell script it executes in the current shell rather than starting a new shell. Type bash to get the behaviour you want.

share|improve this answer

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.