if [ "$1" = "abc" ]; then
echo "found $1"
exit 0
else
echo "not found $1"
exit 1
when i execute test_abc.sh .. i only get the following in the log
found abc
My motive is that all the shell commands in test_abc.sh are run and i get the status of each of them in the test.log. But it seems like 'exit 0' and 'exit 1' are not working in my favor and are logging me out. Request your expert help here.
First hint:
Please close your if-construct with fi !
if expression
then
then-commands...
else
else-commands...
fi
maybe it works not as you suspect. But it works. The exit status is not printed, it is only set. You get your exit status with: $? And $? ist set new after every command. So if you want to get the exit status, you must read it directly after the command execution, or it is overwritten with the exit status of the next command.
Ahh. The new answer shows what I've missed to read.
What's regarding the logout is the way you are calling your scripts:
. ./test.sh bla blub
calling a script with the dot-command(=".") is special. Dot means: don't create a new process. Run the Programm in the current process. And when you call the builtin exit in your script, your current shell is closed - as you requested by this command.
Simple solution: Don't use the dot command. Just call your script: