Re: bug: return doesn't accept negative numbers

2011-08-11 Thread Linda Walsh
` Stephane CHAZELAS wrote: 2011-08-08, 13:55(-07), Linda Walsh: [...] 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 th

Re: bug: return doesn't accept negative numbers

2011-08-11 Thread Jon Seymour
On Mon, Aug 8, 2011 at 8:42 AM, Bob Proulx wrote: > > People sometimes read the POSIX standard today and think it is a > design document.  Let me correct that misunderstanding.  It is not. > POSIX is an operating system non-proliferation treaty. Love it! jon.

Re: bug: return doesn't accept negative numbers

2011-08-11 Thread Stephane CHAZELAS
2011-08-08, 13:55(-07), Linda Walsh: [...] > 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 limi

Re: bug: return doesn't accept negative numbers

2011-08-09 Thread Chet Ramey
On 8/9/11 8:53 AM, Eric Blake wrote: > 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

Re: bug: return doesn't accept negative numbers

2011-08-09 Thread Eric Blake
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

Re: bug: return doesn't accept negative numbers

2011-08-08 Thread Linda Walsh
Chet Ramey wrote: 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. That explains why I never ran into this before!

Re: bug: return doesn't accept negative numbers

2011-08-08 Thread Chet Ramey
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.

Re: bug: return doesn't accept negative numbers

2011-08-08 Thread Mike Frysinger
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 'ex

Re: bug: return doesn't accept negative numbers

2011-08-08 Thread Chet Ramey
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

Re: bug: return doesn't accept negative numbers

2011-08-08 Thread Linda Walsh
Bob Proulx wrote: Linda Walsh wrote: Bob Proulx wrote: Exit codes should be in the range 0-255. --- I suppose you don't realize that 'should' is a subjective opinion that sometimes has little to do with objective reality. Sigh. Okay. Keep in mind that turn about is fair play. Yo

Re: bug: return doesn't accept negative numbers

2011-08-08 Thread Linda Walsh
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 'exi

Re: bug: return doesn't accept negative numbers

2011-08-08 Thread Eric Blake
On 08/07/2011 02:35 PM, Linda Walsh wrote: Eric Blake wrote: On 08/05/2011 05:41 PM, Linda Walsh wrote: Seem to fail on any negative number, but 'exit status' is defined as a short int -- not an unsigned value (i.e. -1 would return 255). In bash, 'return -- -1' sets $? to 255 (note the --).

Re: bug: return doesn't accept negative numbers

2011-08-07 Thread Linda Walsh
Chet Ramey wrote: 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 all

Re: bug: return doesn't accept negative numbers

2011-08-07 Thread Bob Proulx
Linda Walsh wrote: > Bob Proulx wrote: > >Exit codes should be in the range 0-255. > --- > I suppose you don't realize that 'should' is a subjective opinion that > sometimes has little to do with objective reality. Sigh. Okay. Keep in mind that turn about is fair play. You are giving it t

Re: bug: return doesn't accept negative numbers

2011-08-07 Thread Chet Ramey
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 e

Re: bug: return doesn't accept negative numbers

2011-08-07 Thread Chet Ramey
On 8/7/11 4:35 PM, Linda Walsh wrote: > --- > How about portable code using: > > (exit -1); return return $(( -1 & 255 )) -- ``The lyf so short, the craft so long to lerne.'' - Chaucer ``Ars longa, vita brevis'' - Hippocrates Chet Ramey, ITS, CWRUc...@case.eduh

Re: bug: return doesn't accept negative numbers

2011-08-07 Thread Linda Walsh
Bob Proulx wrote: Linda Walsh wrote: How about portable code using: (exit -1); return It's ugly, but would seem to be the portable/official way to do this. Exit codes should be in the range 0-255. --- I suppose you don't realize that 'should' is a subjectiv

Re: bug: return doesn't accept negative numbers

2011-08-07 Thread Bob Proulx
Linda Walsh wrote: > How about portable code using: > > (exit -1); return > > It's ugly, but would seem to be the portable/official way to > do this. Exit codes should be in the range 0-255. Bob

Re: bug: return doesn't accept negative numbers

2011-08-07 Thread Linda Walsh
Eric Blake wrote: On 08/05/2011 05:41 PM, Linda Walsh wrote: Seem to fail on any negative number, but 'exit status' is defined as a short int -- not an unsigned value (i.e. -1 would return 255). In bash, 'return -- -1' sets $? to 255 (note the --). But since that is already an extension (P

Re: bug: return doesn't accept negative numbers

2011-08-05 Thread Linda Walsh
Linda Walsh wrote: Seem to fail on any negative number, but 'exit status' is defined as a short int -- not an unsigned value (i.e. -1 would return 255). Bob Proulx wrote: Eric Blake wrote: Linda Walsh wrote: I guess I don't use negative return codes that often in shell, but I use them a

Re: bug: return doesn't accept negative numbers

2011-08-05 Thread Dennis Williamson
return (and exit) returns an exit code between 0 and 255. Zero means true and anything else means false If you want a function to "return" a value, use printf or echo. On Fri, Aug 5, 2011 at 6:41 PM, Linda Walsh wrote: > > > > I guess I don't use negative return codes that often in shell, but >

Re: bug: return doesn't accept negative numbers

2011-08-05 Thread Bob Proulx
Eric Blake wrote: > Linda Walsh wrote: > >I guess I don't use negative return codes that often in shell, but > >I use them as exit codes reasonably often. For all of the reasons Eric mentioned you won't ever actually be able to see a negative result of an exit code however. > >'return' barfs on "

Re: bug: return doesn't accept negative numbers

2011-08-05 Thread Eric Blake
On 08/05/2011 05:41 PM, Linda Walsh wrote: I guess I don't use negative return codes that often in shell, but I use them as exit codes reasonably often. 'return' barfs on "return -1"... Since return is defined to take no options, and ONLY an integer, as the return code, it shouldn't be hard to