NetBSD-Bugs archive

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

Re: bin/37493: /bin/sh exits if shift fails, but shouldn't

The following reply was made to PR bin/37493; it has been noted by GNATS.

From: David Holland <>
To: Alan Barrett <>
Subject: Re: bin/37493: /bin/sh exits if shift fails, but shouldn't
Date: Sun, 25 May 2008 17:16:02 +0000

 On Sun, May 25, 2008 at 09:49:53AM +0000, Alan Barrett wrote:
  > shift is required to be a special built-in utility
  > <>.
 Well, then...
  > According to one part of SUSv3, syntax errors in
  > special built-in utilities are permitted, but
  > not required, to make the shell exit immediately
  > According to another part of SUSv3, an "option or operand error"
  > in a special built-in utility means that the shell must exit
  > I think that trying to shift too many parameters would fall under this
  > category.
 Well, no. It says "Utility syntax error (option or operand error)",
 and it doesn't define this any more specifically anywhere in the whole
 chapter. At least that I can find. I don't see that an out-of-range
 value qualifies as a syntax error.
 Meanwhile, the definition of shift explicitly says that its exit
 status is nonzero if the count is out of range, which would be
 meaningless if the shell were required to exit in this context.
 By the magical properties of reasoning about standards, it therefore
 must not be required to exit in this context.
 (I see Greg A. Woods has deployed approximately the same reasoning...)
  > > Also... ksh exhibits the same behavior. So, apparently, does the
  > > original Bourne shell. bash and zsh do not. Which makes it unclear if
  > > it's really a bug or not, too...
  > I say "not a bug".
 Nah, it's clearly allowed by POSIX, but I don't think we can claim
 it's required, and it's certainly not *desirable* behavior.
 Fixing it, on the other hand, will require a considerable rework of
 error handling in sh, which I don't think would be a good idea this
 David A. Holland

Home | Main Index | Thread Index | Old Index