bug-bash
[Top][All Lists]
Advanced

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

Re: read builtin and readonly variables


From: Chet Ramey
Subject: Re: read builtin and readonly variables
Date: Tue, 04 Jan 2011 10:25:37 -0500
User-agent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.2.13) Gecko/20101207 Thunderbird/3.1.7

On 1/4/11 10:05 AM, Eric Blake wrote:
> On 01/03/2011 11:41 PM, Jan Schampera wrote:
>> Hello list,
>>
>>
>> the read builtin command, when trying to assign to a readonly variable
>> after reading the data, spits an error message. This is fine.
>>
>> But the return status is 0. It "always" (down to 2.04 was tested) has
>> been like that, and it's like that in upcoming 4.2.
>>
>> For me, this doesn't make sense. The read may have been successful, but
>> the data is gone. It would make sense to return !=0 here, IMHO.
> 
> getopts also suffers from a difference in behavior between shells on
> readonly arguments:
> 
> $ ksh -c 'readonly foo; getopts a: foo -a blah; echo $?'
> ksh[1]: ksh: foo: is read only
> $ echo $?
> 2
> $ bash -c 'readonly foo; getopts a: foo -a blah; echo $?'
> bash: foo: readonly variable
> 1
> 
> where non-interactive ksh completely exited on an invalid assignment,
> but bash merely set $?.

The shell should not exit on an assignment error with getopts, since
getopts is not a special builtin.

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



reply via email to

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