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: Eric Blake
Subject: Re: bug: return doesn't accept negative numbers
Date: Tue, 09 Aug 2011 06:53:41 -0600
User-agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.18) Gecko/20110621 Fedora/3.1.11-1.fc14 Lightning/1.0b3pre Mnenhy/0.8.3 Thunderbird/3.1.11

On 08/08/2011 08:14 PM, Chet Ramey wrote:
On 8/8/11 9:42 PM, Mike Frysinger wrote:
On Monday, August 08, 2011 21:20:29 Chet Ramey wrote:
On 8/8/11 8:53 AM, Eric Blake wrote:
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.

That's a reasonable extension to consider for the next release of bash.

i posted a patch for this quite a while ago.  not that it's hard to code.

Sure.  It's just removing the three lines of code that were added
between bash-3.2 and bash-4.0.  The question was always whether that's
the right thing to do, and whether the result will behave as Posix
requires.

Yes, the result will behave as POSIX requires. POSIX requires that 'return' and 'exit' need not support '--' (since they are special builtins that do not specifically require compliance with the generic rules on option parsing), that they need not support options, and that if their optional argument is present, it need not be supported if it is not a non-negative integer no greater than 255. But they are _not_ required to reject any input outside the above constraints - therefore, an extension that supports '--', an extension that parses '-- -1' as 255, and an extension that parses any option that looks like a negative number such as 'exit -1', are ALL valid extensions permitted by POSIX, and need not be disabled by --posix, but can be available always. ksh does just that: 'return -1' and 'return -- -1' are always accepted and both result in the same behavior as the POSIX-mandated 'return 255'; ksh also has an extension where 'return --help' prints help, although bash uses 'help return' for this purpose.

--
Eric Blake   address@hidden    +1-801-349-2682
Libvirt virtualization library http://libvirt.org



reply via email to

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