Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does `return -1 || exit -1` mean?

Tags:

bash

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.

like image 355
Hai Vu Avatar asked Apr 18 '16 02:04

Hai Vu


People also ask

What means return code?

(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.

What is return code in SAP?

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.

What is return code C++?

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.

Is Exit an code?

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.


1 Answers

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.

like image 139
heemayl Avatar answered Sep 30 '22 16:09

heemayl