简体   繁体   中英

Why do many init.d scripts end in “exit $?”?

I've seen a lot of strange quirks in CentOS 6.5's init.d scripts, but one pattern I've seen at the end of most of these scripts is

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

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

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

It's actually not really necessary to explicitly specify $? but scripters probably just include it to be clear about what it intends to do.

exit: exit [n]

Exit the shell.

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

I also hope you don't actually mean eend $? of OpenRC :

eend retval [string ]

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

See source .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM