5

exit with zero or one numeric argument like exit or exit 42 print "exit" and exit the shell.

exit with an invalid argument like exit hello prints an error message, prints "exit" and exits the shell with return value 255.

exit in a pipe, for example exit | cat | exit does not print "exit" and the return value of this command depends on which version of bash we're using. This does not exit the shell.

exit with multiple arguments, like, exit 1 2 3 prints an error message, prints "exit" but does not exit the shell.

This means that sometimes bash will print "exit" without actually exiting, which can be very confusing. Is this a bug or does this make sense for some reason?

3
  • @jesse_b, I can with 5.1, and with the current code from the development repository Feb 10 at 13:20
  • Disregard me I have a function replacing the normal exit command that disregards any additional arguments, I was using \exit but I guess that didn't work. command exit reproduces
    – jesse_b
    Feb 10 at 13:24
  • 1
    exit hello world and exit foo 1 will error but still exit so it seems only if the first argument is a valid number will it run into this.
    – jesse_b
    Feb 10 at 13:26

1 Answer 1

0

Bash prints "exit" when it is about to exit a non-login shell, and prints "logout" (or equivalent in a locale used) when it is about to exit a login shell. Therefore I guess that this message is printed exactly to distinguish these two cases from user point of view (when you log out from eg. a ssh session to a remote system and return to the local one, such an information may be helpful, if your system prompt does not include the hostname).

The case you mentioned (exit 1 2 3), where bash prints "exit" but does not exit (and prints an error message instead, after printing "exit") should be considered a design error, I think. exit should parse arguments and print an optional error message before printing "exit" or "logout". The latter should be printed only in case of a successful parameter check. You can file a bug if you think this is confusing.

1
  • 1
    Is there a way to find out if it has already been reported? Feb 10 at 21:13

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .