bug-bash
[Top][All Lists]
Advanced

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

Re: Unsuccessful assignment of a readonly variable does not return 1


From: Chet Ramey
Subject: Re: Unsuccessful assignment of a readonly variable does not return 1
Date: Mon, 12 Dec 2016 15:06:12 -0500
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.11; rv:45.0) Gecko/20100101 Thunderbird/45.5.1

On 12/12/16 5:11 AM, Laur Aliste wrote:
> 
> Hi,
> is it accepted behavior for a failing assignment of a readonly variable to
> return successfully?

The readonly builtin did not fail; the variable `j' was set readonly, and,
as a side effect, the shell assigned it the null string.

The assignment to i fails because Posix says it should:

"If there is no command name, but the command contained a command
substitution, the command shall complete with the exit status of the last
command substitution performed."

http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_09_01

> 
> See following code:
> 
> fail() {
>     return 1
> }
> 
> o() {
>     local i j
> 
>     i="$(fail)" || echo "i init failed"
>     readonly j="$(fail)" || echo "j init failed"  # this echo is not executed
> }




-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer
                 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU    address@hidden    http://cnswww.cns.cwru.edu/~chet/



reply via email to

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