[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Help-bash] Is `readonly` too strict?
From: |
Chet Ramey |
Subject: |
Re: [Help-bash] Is `readonly` too strict? |
Date: |
Thu, 22 Feb 2018 10:42:03 -0500 |
User-agent: |
Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:52.0) Gecko/20100101 Thunderbird/52.6.0 |
On 2/22/18 1:58 AM, Peng Yu wrote:
> Hi,
>
> Running `main.sh` shows an error. But `x` is set for `script.sh` not
> `main.sh`. So I think that there should not be an error message. Is
> `readonly` interpreted too strictly in bash?
No. Posix has this to say when discussing variable assignments that precede
a simple command:
"If any of the variable assignments attempt to assign a value to a variable
for which the readonly attribute is set in the current shell environment
(regardless of whether the assignment is made in that environment), a
variable assignment error shall occur."
http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_09_01
--
``The lyf so short, the craft so long to lerne.'' - Chaucer
``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU address@hidden http://tiswww.cwru.edu/~chet/