bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: inconsistent readonly error behavior


From: Chet Ramey
Subject: Re: inconsistent readonly error behavior
Date: Wed, 23 Dec 2020 10:09:40 -0500
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:78.0) Gecko/20100101 Thunderbird/78.5.1

On 12/22/20 12:21 PM, Travis Everett wrote:
I don't understand what distinction you're trying to make; any example you
can give?

I added an extra near-copy of the script to the gist replacing the
assignment with unset

`unset' is a different thing. It's a special builtin, so POSIX requires a non-interactive shell to exit when it fails. The question is whether or not
attempting to unset a readonly variable counts as a failure; the standard
says only "Read-only variables cannot be unset" and doesn't require it to
be an error. Behavior varies.

(
https://gist.github.com/abathur/8d18853e06f2a8cf3a97e45acda17f68#file-unset-sh-console),
and corresponding output where you can see that it hits all of the lines
skipped in the assignment example. (The behavior in this example is in line
with what I see by replacing the assignment with other errors like a
missing command, or a ${parameter:?word} expansion.)

A `missing command' is not a shell error. An expansion error requires the shell to exit under the same conditions as a variable assignment error, and
the bash behavior in posix and default modes is the same.

--
``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/



reply via email to

[Prev in Thread] Current Thread [Next in Thread]