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    c...@case.edu    http://cnswww.cns.cwru.edu/~chet/

Reply via email to