I'm confused by the following bash line, written by someone else:
return -1 || exit -1
What does it mean? I understand the ||
construct means if the first part (in this case, return -1
) failed (i.e. return a non-zero code), then the second part (exit -1
) is executed. What's also strange is this statement is not part of any function, but in the main body of the script.
I appreciate someone who explains this to me.
(1) A message, typically numeric, that is sent by a function, program or server back to the program that called it in order to report the outcome of the processing. Also called an "exit code." See HTTP return codes.
Return Code. Background. The most prominent system field should be the return code sy-subrc. This indicates the successful execution of an ABAP statement or, if you are using classic exceptions, a procedure. A return code of 0 usually means that the execution was successful.
The value supplied as an argument to exit is returned to the operating system as the program's return code or exit code. By convention, a return code of zero means that the program completed successfully. You can use the constants EXIT_FAILURE and EXIT_SUCCESS , also defined in <stdlib.
What Does Exit Code Mean? An exit code or exit status is a number that is returned by an executable to show whether it was successful. This is also sometimes called a return code, or in some cases, an error code, although the terminology here may be slightly different.
Here, return
is a trick to exit when the script is source
-ed and exit
is usual that it will exit a shell.
So essentially the above condition is to exit from the execution loop of the script whether it is source
-ed or executed.
Also note that, the negative return values are not supported in bash
. In both cases, you would get exit status of 255, not -1.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With