Perl Question About Process Exit Status

In a Perl script I have the following:

/path/to/my/binary/executable/doSomething myargs status=?
echo “doSomething exit status = $status”


This echoes: “doSomething exit status = 2.”

What does “2” mean?

That doesn’t look anything like Perl. It looks like a shell script, though.

The 2 is the value returned by the program to the shell after it exits. (In other words, whatever is returned from its main() function or a call to exit(), depending on the language.)

Exit statuses let you check to make sure the program succeeded or failed. A non-zero status often indicates the program failed in some way.

That doesn’t look much like perl…

The short and pretty useless answer is that 2 is the exit status that the doSomething program returned. That program called exit with an argument of two, which was passed on to its parent, your shell, which has thoughtfully stored for you in the variable $?.

Its meaning, or whether it means anything at all, is highly dependent on the design & implementation of DoSomething. In Unix-land it’s conventional for programs to exit with zero if everything went as expected, but there’s no specific meaning assigned to non-zero values, and even this is just a convention that can easily be ignored by programmers.

ETA: Or what friedo said much more succinctly than I.