You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Can only exit with status 0-255. Other data should be written to stdout/stderr.
Problematic code:
exit"Bad filename"
Correct code:
echo"Bad filename">&2exit 1
Rationale:
exit can only be used to signal success or failure (0 = success, 1-255 = failure). It can not be used to return string data, and it can not be used to print error messages.
String data should be written stdout, before an exit 0 to exit with success.
Errors should instead be written to stderr, with an exit 1 (or higher) to exit with failure:
if [ !-f"$1" ]
thenecho"$1 is not a regular file">&2exit 1
fi
Note in particular that exit -1 is equivalent to exit 255, but that exit 1 is the more canonical way of expressing the first possible error code.