[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Some minor notes on manual chapter 4 "Shell Builtin Commands"
From: |
Chet Ramey |
Subject: |
Re: Some minor notes on manual chapter 4 "Shell Builtin Commands" |
Date: |
Mon, 9 Oct 2023 10:35:20 -0400 |
User-agent: |
Mozilla Thunderbird |
On 10/8/23 7:16 PM, Martin Schulte wrote:
The following has been tested with bash 5.2.15:
- 3.7.5 Exit Status says: "All builtins return an exit status of 2 to indicate
incorrect usage, generally invalid options or missing arguments." but cd with two or
more non-optional arguments returns an exit status of 1.
There is surprising variance in behavior here, from a status of 2 to 1
to 0 (dash), plus the silly ksh "substitute old for new in $PWD," which
the NetBSD sh (!) also performs. I agree that a status of 2 is reasonable.
The historical sh behavior is to ignore additional arguments.
- The same is true if exit is called with two or more argument where the first
is numeric. This exit doesn't terminate bash.
More varying behavior. ash-based shells (dash, BSD sh, etc.) ignore any
additional arguments -- the historical sh behavior. bash and yash treat
it as a non-fatal error. mksh treats it as a fatal error, which I suppose
it can because `exit' is a posix special builtin. Posix makes it all
explicitly unspecified, even whether the return status is non-zero.
- When exit is invoked with a non-numeric first argument it terminates bash.
That seems to be inconsistent with the behaviour described before, while the
exit status of the shell is 2 and consistent in some way.
Everyone does this (including the exit status of 2) except ksh93, which
simply ignores any error and exits with a 0 status. Posix makes the
behavior unspecfied.
--
``The lyf so short, the craft so long to lerne.'' - Chaucer
``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU chet@case.edu http://tiswww.cwru.edu/~chet/