0

I was creating a init.d service, and was reading a few scripts for reference. I found this one in a skeleton:

What does this snippet do? I get that this is a switch:case. I am asking about the case within the case.

case "$1" in
  start)
        echo test
        case "$?" in
                0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
                2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
        esac

PS: Excuse the title, I couldn't think of a better name

Thanks.

1
  • 1
    What this snippet does is syntax error, since it is incomplete.
    – sorpigal
    Jan 19, 2011 at 12:18

2 Answers 2

2

Seems like the actual script might have had something more substantial than 'echo test'. $? is the exit code returned by the echo command in this script. The inner case statement prints the log message that is appropriate for the termination code. 0|1 most likely is success. 2 is probably an error.

2
  • I just have this line: cd /usr/share/jetty; /usr/bin/java -jar start.jar Jan 19, 2011 at 10:57
  • In that case, it will check the exit status of the java process. Jan 19, 2011 at 11:24
0

$? holds the exit code of the last executed command. If 0 - there were no errors.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.