[Top][All Lists]

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

Re: Assign read-only variables return code not usable inline

From: Chet Ramey
Subject: Re: Assign read-only variables return code not usable inline
Date: Tue, 23 Feb 2021 16:11:28 -0500
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:78.0) Gecko/20100101 Thunderbird/78.7.1

On 2/23/21 7:54 AM, Léa Gris wrote:

#!/usr/bin/env bash

declare -r r

r=2 || exit 2

OK, let's pick this one. This is what POSIX calls a "variable assignment
error" in


(you've omitted the error messages bash prints).

POSIX says a non-interactive shell must exit, which bash does in posix mode. An interactive shell doesn't exit, but POSIX says

"the shell shall not perform any further processing of the command in which the error occurred."

That command is the and-or list the shell is executing; the shell jumps
back to the top-level processing loop. Bash does this in interactive and
non-interactive shells in default mode.

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