1

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.

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

here is the output:

[root@ip-10-251-86-31 ebs_raid]# . test.sh 
ok
[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.

  • 2
    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
3

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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