Debian Bug report logs - #1101388
dash: POSIX behavior / shift N calls exit if N > $# (positional arg count)

version graph

Package: dash; Maintainer for dash is Andrej Shadura <[email protected]>; Source for dash is src:dash (PTS, buildd, popcon).

Reported by: Jari Aalto <[email protected]>

Date: Wed, 26 Mar 2025 20:54:01 UTC

Severity: normal

Tags: upstream

Found in version dash/0.5.12-12

Reply or subscribe to this bug.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to [email protected], Andrej Shadura <[email protected]>:
Bug#1101388; Package dash. (Wed, 26 Mar 2025 20:54:02 GMT) (full text, mbox, link).


Acknowledgement sent to Jari Aalto <[email protected]>:
New Bug report received and forwarded. Copy sent to Andrej Shadura <[email protected]>. (Wed, 26 Mar 2025 20:54:02 GMT) (full text, mbox, link).


Message #5 received at [email protected] (full text, mbox, reply):

From: Jari Aalto <[email protected]>
To: Debian Bug Tracking System <[email protected]>
Subject: dash: POSIX behavior / shift N calls exit if N > $# (positional arg count)
Date: Wed, 26 Mar 2025 22:35:05 +0200
[Message part 1 (text/plain, inline)]
Package: dash
Version: 0.5.12-12
Severity: normal
Tags: upstream

Problem:

   set -- 1
   shift 2
   ... causes program to exit

The exit is a bit unexpected as the whole
program terminates. Suggested change:

   1. shift all positional parameters
   2. set status code $?
   3. continue execution

   This would also be allowed by POSIX:
   Bash and Zsh behaves like this. 

This would make it possible to write code:

   set -- 1
   if shift 2 ; then
      ... do something, a warning message to user ...
   fi
   ... continue

Caveat: I'm aware of this, but perhaps
the default behaviour with N could be
chnaged to be more script friendly.

     shift $#

See also attached test script.

CONSEQUENCES OF ERRORS

Program execution is interrupted and
program cannot do any error handling of
their own.

Ref: POSIX 2018 (shift):

    https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_25_01

    EXIT STATUS

    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.

-- System Information:
Debian Release: trixie/sid
  APT prefers testing
  APT policy: (500, 'testing')
Architecture: amd64 (x86_64)

Kernel: Linux 6.1.0-6-amd64 (SMP w/4 CPU threads; PREEMPT)
Locale: LANG=C.UTF-8, LC_CTYPE=C.UTF-8 (charmap=UTF-8), LANGUAGE not set
Shell: /bin/sh linked to /usr/bin/dash
Init: systemd (via /run/systemd/system)
LSM: AppArmor: enabled

Versions of packages dash depends on:
ii  debianutils  5.21
ii  libc6        2.40-6

dash recommends no packages.

dash suggests no packages.

-- debconf information:
  dash/ineffectivediversion:
* dash/sh: true
[x-portability-posix-special-builtin-shift-n.sh (text/plain, attachment)]

Send a report that this bug log contains spam.


Debian bug tracking system administrator <[email protected]>. Last modified: Tue May 13 13:44:21 2025; Machine Name: bembo

Debian Bug tracking system

Debbugs is free software and licensed under the terms of the GNU General Public License version 2. The current version can be obtained from https://bugs.debian.org/debbugs-source/.

Copyright © 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson, 2005-2017 Don Armstrong, and many other contributors.