I am trying to exit the script from a function.
I was in assumption that if we use exit ( inside or outside the function) it will exit from the script.
alternatively, return will exit from that particular function.
but in my case, exit is exiting from the function and not the script.
I am using exit in a subfunction.
is there any other way to completly exit from the script at any location?
Hi, if I'm xell understanding, what you want is that if you have no arguments in your function DoExit, you exit the main program.
In this case, you can test the exit value after your function :
if (test $? -eq 0);then
your code for normal execution
else
exit 1
fi
$? return the value of the exit variable. e.g :
pwd % ll
total 108
all my files in my directory
coral22:kevin/res/test2 % echo $?
0
pwd % azerty
-bash: azerty: command not found
pwd % echo $?
127