[Top][All Lists]

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

Re: inconsistent readonly error behavior

From: Travis Everett
Subject: Re: inconsistent readonly error behavior
Date: Wed, 23 Dec 2020 10:10:39 -0600

I think I'm missing or misreading something. If I understood, the
assignment and expansion errors are both shell errors that should have the
same exit behavior?

But I see the assignment error ending the list and returning to the top
level, and the expansion exiting the script:

readonly sigh=1
if true; then
echo reached1
echo reached2
if true; then
echo ${bad:?word}
echo reached3
echo reached4


./shell_error.sh: line 5: sigh: readonly variable
./shell_error.sh: line 8: bad: word

On Wed, Dec 23, 2020 at 9:09 AM Chet Ramey <chet.ramey@case.edu> wrote:

> 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]