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: Chet Ramey
Subject: Re: bug: return doesn't accept negative numbers
Date: Sun, 07 Aug 2011 18:15:02 -0400
User-agent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; en-US; rv:1.9.2.18) Gecko/20110616 Lightning/1.0b2 Thunderbird/3.1.11

On 8/7/11 6:03 PM, Linda Walsh wrote:

> Bash itself is inconsistent in that it accepts exit values the same as
> every other
> program, but limits return values to a particular subset.

Bash accepts any value you want to give to `return' and strips it to
8 bits, as the standard allows.  Read the error message closely: it says
`invalid option'.  return doesn't accept any options, even ones that
might possibly be interpreted as negative status values -- which the
standard doesn't allow anyway.  As Eric Blake showed, `return -- -1' works
just fine, and sets $? to 255.  If you don't want to type the three extra
characters, use the $(( ... )) idiom I posted earlier.

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]