Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does a bash script have return code itself?

I know the return code will be contained in $? after a command was executed, but what does $? mean after a script was executed? The return code of the last command in that script?

Can I tell if a script has been excuted from head to tail and not interrupted by some unexpected system halt or something?

If I have a script like below excuted,

Command A;
if [ $? -eq 0]
then
echo "OK" >> log
else
echo "failed" >> log
fi

and the system halted while A was running, what will I find in that log file? "OK", "failed" or nothing?

like image 543
erical Avatar asked Dec 27 '22 09:12

erical


1 Answers

  1. Yes, or the value passed after exit, e.g. exit 31.

  2. Not without taking measures within the other script to make it explicit.

like image 149
Ignacio Vazquez-Abrams Avatar answered Jan 08 '23 11:01

Ignacio Vazquez-Abrams