Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > gnu.bash.bug > #14784
| Path | csiph.com!goblin1!goblin.stu.neva.ru!usenet.stanford.edu!not-for-mail |
|---|---|
| From | Eric Blake <eblake@redhat.com> |
| Newsgroups | gnu.bash.bug |
| Subject | Re: exiting noninteractive shells on 'shift 2' |
| Date | Fri, 9 Nov 2018 08:47:30 -0600 |
| Organization | Red Hat, Inc. |
| Lines | 45 |
| Approved | bug-bash@gnu.org |
| Message-ID | <mailman.3742.1541774877.1284.bug-bash@gnu.org> (permalink) |
| References | <cd413815-9523-f280-3ef3-fcd21bf7119e@redhat.com> <d8601773-69c8-16d1-82ab-5068d63bb24d@case.edu> |
| NNTP-Posting-Host | lists.gnu.org |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=utf-8; format=flowed |
| Content-Transfer-Encoding | 7bit |
| X-Trace | usenet.stanford.edu 1541774878 11305 208.118.235.17 (9 Nov 2018 14:47:58 GMT) |
| X-Complaints-To | action@cs.stanford.edu |
| To | chet.ramey@case.edu, bug-bash <bug-bash@gnu.org> |
| Envelope-to | bug-bash@gnu.org |
| User-Agent | Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.3.0 |
| In-Reply-To | <d8601773-69c8-16d1-82ab-5068d63bb24d@case.edu> |
| Content-Language | en-US |
| X-Scanned-By | MIMEDefang 2.79 on 10.5.11.12 |
| X-Greylist | Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.41]); Fri, 09 Nov 2018 14:47:32 +0000 (UTC) |
| X-detected-operating-system | by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] |
| X-Received-From | 209.132.183.28 |
| X-BeenThere | bug-bash@gnu.org |
| X-Mailman-Version | 2.1.21 |
| Precedence | list |
| List-Id | Bug reports for the GNU Bourne Again SHell <bug-bash.gnu.org> |
| List-Unsubscribe | <https://lists.gnu.org/mailman/options/bug-bash>, <mailto:bug-bash-request@gnu.org?subject=unsubscribe> |
| List-Archive | <http://lists.gnu.org/archive/html/bug-bash/> |
| List-Post | <mailto:bug-bash@gnu.org> |
| List-Help | <mailto:bug-bash-request@gnu.org?subject=help> |
| List-Subscribe | <https://lists.gnu.org/mailman/listinfo/bug-bash>, <mailto:bug-bash-request@gnu.org?subject=subscribe> |
| Xref | csiph.com gnu.bash.bug:14784 |
Show key headers only | View raw
On 11/8/18 6:03 PM, Chet Ramey wrote: > On 11/8/18 3:37 PM, Eric Blake wrote: >> If I'm reading POSIX correctly, shift is a special built-in utility, and if >> '$#' is 0 or 1, then 'shift 2' counts as a utility error that shall exit >> the shell, per the table in 2.8.1 Consequences of Shell Errors: >> >> http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_08_01 >> >> >> >> dash gets this right: >> >> $ dash -c 'set 1 >>> shift 2 >>> echo "oops"' >> dash: 2: shift: can't shift that many >> >> but bash happily lets 'shift 2' fail with $? set to 1 but continues on with >> execution of the rest of the script, even when in POSIX mode: > > As you later note: > > "If the n operand is invalid or is greater than "$#", this may be > considered a syntax error and a non-interactive shell may exit; if the > shell does not exit in this case, a non-zero exit status shall be returned. > Otherwise, zero shall be returned." > > So the bash behavior is not a conformance issue, and allowed by the > standard. Well, there's STILL a conformance issue - the standard requires that unless documented otherwise, any time a command line tool exits with non-zero status, that it outputs a message to stderr explaining the error. The page for 'shift' does not document an exception for an exit status of 1 being silent, yet bash is completely silent when 'shift 2' returns non-zero status. Producing an error message to stderr would call the developer's attention to the bug in their script and the fact that bash did not shift out 1 argument, whether or not you also change bash to exit the script or continue with execution. -- Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3266 Virtualization: qemu.org | libvirt.org
Back to gnu.bash.bug | Previous | Next | Find similar | Unroll thread
Re: exiting noninteractive shells on 'shift 2' Eric Blake <eblake@redhat.com> - 2018-11-09 08:47 -0600
csiph-web