Why do many init.d scripts end with "exit $?"

I saw a lot of weird quirks in the init.d CentOS 6.5 scripts, but the one template I saw at the end for most of these scripts is

case "$1" in # ... commands here esac exit $? 

What is the purpose of " exit $? " Here?

+5
source share
1 answer

It returns a script return code of the last significant command to the calling init system. Whenever a command exits, the return code is stored on $? shell.

$? it really not necessary to explicitly specify $? but the scriptwriters probably just include him to be clear about what he intends to do.

exit: exit [n]

Exit from the shell.

Exiting a shell with a status of N. If N is omitted, the exit status is the command of the last command executed.

I also hope that you really do not mean eend $? of OpenRC :

eend retval [string]

If retval is not 0, then print the string using eerror and !! in square brackets at the end of the line. Otherwise, print ok in square brackets at the end of the line. The retval value is returned.

See the source .

+5
source

Source: https://habr.com/ru/post/1200579/


All Articles