* [BUG] 'trap' is not quite POSIX compliant
@ 2016-02-13 15:45 Martijn Dekker
2016-02-13 16:08 ` Harald van Dijk
2016-02-15 18:46 ` Chet Ramey
0 siblings, 2 replies; 3+ messages in thread
From: Martijn Dekker @ 2016-02-13 15:45 UTC (permalink / raw)
To: dash
The 'trap' command in dash is not compliant with POSIX. According to the
spec, both '-' and any unsigned decimal integer should be accepted as an
argument meaning 'unset this trap'; dash only accepts '-'.
http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_28
I did testing on all other POSIX shells I know of with this little script:
trap 'echo BYYYE' EXIT
trap "$1" EXIT
This script will either produce 'BYYYE' or output a "command not found"
error message, depending on whether $1 was accepted as an argument for
unsetting the trap.
None of the shells are technically compliant: they only interpret an
unsigned decimal integer up to a certain value as 'unset this trap'; a
value exceeding that is interpreted as a command.
Interestingly, that maximum value differs slightly between shells. So
far, I've found:
- dash and Busybox ash do not accept any.
- bash, yash, pdksh, mksh/lksh, FreeBSD /bin/sh, and AT&T ksh "AJM 93u+
2012-08-01" accept up to 31.
- AT&T ksh "M 1993-12-28 s+" accepts up to 32.
- zsh 4.3.11, zsh 5.1.1 and zsh 5.2-dev-1 (current git) on my Mac accept
up to 33.
- zsh 5.0.2 on FreeBSD accepts up to 34.
For compatibility purposes it might seem wise to follow the majority of
implementations, accepting up to 31.
By the way, dash and zsh, as well as bash in non-POSIX mode, also accept
the counterintuitive and non-POSIX-compliant form "trap EXIT" to unset
the trap, but other shells don't: bash (POSIX), yash and ksh93 produce
an error, while mksh/lksh silently ignore that form. What a mess...
- M.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [BUG] 'trap' is not quite POSIX compliant
2016-02-13 15:45 [BUG] 'trap' is not quite POSIX compliant Martijn Dekker
@ 2016-02-13 16:08 ` Harald van Dijk
2016-02-15 18:46 ` Chet Ramey
1 sibling, 0 replies; 3+ messages in thread
From: Harald van Dijk @ 2016-02-13 16:08 UTC (permalink / raw)
To: Martijn Dekker, dash
On 13/02/2016 16:45, Martijn Dekker wrote:
> The 'trap' command in dash is not compliant with POSIX. According to the
> spec, both '-' and any unsigned decimal integer should be accepted as an
> argument meaning 'unset this trap'; dash only accepts '-'.
Indeed. This was reported early December at
<http://www.spinics.net/lists/dash/msg01109.html> along with a patch.
The patch got rejected in its initial form, which would treat any
unsigned decimal integer as a signal number. Its later update treats
unsigned decimal integers as signal numbers only up to NSIG (which is an
OS-dependent value). bash uses a dynamic limit based on NSIG too, except
it adds some specific special numbers for bash-specific traps. I
wouldn't be surprised if it's dynamic in the other shells you tested as
well, and that the shell-specific traps are the reason for the slight
variations in limits you found.
Cheers,
Harald van Dijk
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [BUG] 'trap' is not quite POSIX compliant
2016-02-13 15:45 [BUG] 'trap' is not quite POSIX compliant Martijn Dekker
2016-02-13 16:08 ` Harald van Dijk
@ 2016-02-15 18:46 ` Chet Ramey
1 sibling, 0 replies; 3+ messages in thread
From: Chet Ramey @ 2016-02-15 18:46 UTC (permalink / raw)
To: Martijn Dekker, dash; +Cc: chet.ramey
On 2/13/16 10:45 AM, Martijn Dekker wrote:
> By the way, dash and zsh, as well as bash in non-POSIX mode, also accept
> the counterintuitive and non-POSIX-compliant form "trap EXIT" to unset
> the trap, but other shells don't: bash (POSIX), yash and ksh93 produce
> an error, while mksh/lksh silently ignore that form. What a mess...
The `trap EXIT' is historical Bourne shell behavior, though Posix makes it
an error.
--
``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/
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2016-02-15 18:52 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-02-13 15:45 [BUG] 'trap' is not quite POSIX compliant Martijn Dekker
2016-02-13 16:08 ` Harald van Dijk
2016-02-15 18:46 ` Chet Ramey
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).