Bash Script Exits su or ssh Session Rather than Script

Posted by Russ on Super User See other posts from Super User or by Russ
Published on 2010-04-23T23:00:20Z Indexed on 2010/04/23 23:03 UTC
Read the original article Hit count: 486

Filed under:
|
|

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.

© Super User or respective owner

Related posts about centos

Related posts about bash