Re: `foo=1 declare -r foo' prints an error message but its exit status is zero
On Wednesday, September 9, 2015 2:17:30 PM CDT ziyunfei wrote: > $ foo=1 declare -r foo > bash: foo: readonly variable > $ echo $? > 0 > $ echo $foo > 1 > > Is this a bug? > > $ bar=1 readonly bar; # throw an error in Bash 4.2, fixed in Bash 4.3 It's a bit more illustrative when you use `readonly' instead of `declare'. In the former case bash only prints the error in non-POSIX mode because it modifies the special builtin to unset its value when the command finishes. `declare' will print an error in either mode. If there's any bug here it's that bash fails to bail out and executes the echo command anyway. $ ( for sh in bash sh ksh mksh zsh dash bb posh; do printf '%-5s x=%5s status=%s\n' "${sh}:" "$("$sh" -c "\${ZSH_VERSION+false}||emulate sh; trap 'echo \${x+unset}' EXIT; $( signature.asc Description: This is a digitally signed message part.
Re: `foo=1 declare -r foo' prints an error message but its exit status is zero
On 9/9/15 2:17 AM, ziyunfei wrote: > $ foo=1 declare -r foo > bash: foo: readonly variable > $ echo $? > 0 > $ echo $foo > 1 > > Is this a bug? This has already been changed for the next version of bash. Chet -- ``The lyf so short, the craft so long to lerne.'' - Chaucer ``Ars longa, vita brevis'' - Hippocrates Chet Ramey, ITS, CWRUc...@case.eduhttp://cnswww.cns.cwru.edu/~chet/