bug-bash
[Top][All Lists]
Advanced

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

Re: bug: return doesn't accept negative numbers


From: Linda Walsh
Subject: Re: bug: return doesn't accept negative numbers
Date: Mon, 08 Aug 2011 13:55:32 -0700
User-agent: Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.8.1.24) Gecko/20100228 Thunderbird/2.0.0.24 Mnenhy/0.7.6.666



Eric Blake wrote:
(exit -1); return

That's not portable, either. exit is allowed to reject -1 as invalid. POSIX is clear that exit and return have the same constraints - if an argument is provided, it must be 0-255 to be portable.

However, you are on to something - since bash allows 'exit -1' as an extension, it should similarly allow 'return -1' as the same sort of extension. The fact that bash accepts 'exit -1' and 'exit -- -1', but only 'return -- -1', is the real point that you are complaining about.

----
        Clearly(? :-)), 'return' should accept -1, in 'normal mode',
and both 'exit' and 'return' should return error "ERANGE" if "--posix" is
set, and -1 is given.  Iinvalid option doesn't make as much sense, in
this situtation, if it was -k or -m, sure...but in this case, it's a fact
that --posix artificially limits exit values apart from what is allowed in
most prog langs (which accept negative, but still return results &0xff),
so for Posix, it's a matter of disallowing a 'normal range', vs. it being
an invalid option....

        Would that be sound reasoning?







reply via email to

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