[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: exiting noninteractive shells on 'shift 2'
From: |
Chet Ramey |
Subject: |
Re: exiting noninteractive shells on 'shift 2' |
Date: |
Thu, 8 Nov 2018 19:03:06 -0500 |
User-agent: |
Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 |
On 11/8/18 3:37 PM, Eric Blake wrote:
> If I'm reading POSIX correctly, shift is a special built-in utility, and if
> '$#' is 0 or 1, then 'shift 2' counts as a utility error that shall exit
> the shell, per the table in 2.8.1 Consequences of Shell Errors:
>
> http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_08_01
>
>
>
> dash gets this right:
>
> $ dash -c 'set 1
>> shift 2
>> echo "oops"'
> dash: 2: shift: can't shift that many
>
> but bash happily lets 'shift 2' fail with $? set to 1 but continues on with
> execution of the rest of the script, even when in POSIX mode:
As you later note:
"If the n operand is invalid or is greater than "$#", this may be
considered a syntax error and a non-interactive shell may exit; if the
shell does not exit in this case, a non-zero exit status shall be returned.
Otherwise, zero shall be returned."
So the bash behavior is not a conformance issue, and allowed by the
standard.
--
``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/
- exiting noninteractive shells on 'shift 2', Eric Blake, 2018/11/08
- Re: exiting noninteractive shells on 'shift 2',
Chet Ramey <=
- Re: exiting noninteractive shells on 'shift 2', Eric Blake, 2018/11/09
- Re: exiting noninteractive shells on 'shift 2', Chet Ramey, 2018/11/09
- Re: exiting noninteractive shells on 'shift 2', Eric Blake, 2018/11/09
- Re: exiting noninteractive shells on 'shift 2', Chet Ramey, 2018/11/09
- Re: exiting noninteractive shells on 'shift 2', Eric Blake, 2018/11/09
- Re: exiting noninteractive shells on 'shift 2', Chet Ramey, 2018/11/09
Re: exiting noninteractive shells on 'shift 2', Grisha Levit, 2018/11/08