Op 15-04-18 om 03:03 schreef Philip Guenther:
On Sun, 15 Apr 2018, Martijn Dekker wrote:
$ ksh -c 'trap "" CONT; trap'
trap --  CONT

That is not "suitable for re-entry into the shell". Empty words must be
quoted, or they disappear. Expected output:

trap -- '' CONT

Patch below. OK?

That also changes the output of set, export, and alias:

Yes, but harmlessly. ('readonly -p' and 'typeset', too.)

The change also matches the behaviour of every other POSIXy shell, including AT&T ksh88 and ksh93.

An alternative would be to special-case empty trap actions in the 'trap' builtin, but in my view that would be (a) ugly and (b) asking for future bugs if another builtin ever needs to print separate shell-quoted words.

Are there any regress tests affected by this?

I should have mentioned that I ran them, and the results before and after the patch are identical (11 failed "as expected", 245 passed).

My bikeshed would move the handling into the unquoted case to make it just
a test+set:

--- misc.c      15 Mar 2018 16:51:29 -0000      1.69
+++ misc.c      15 Apr 2018 01:00:31 -0000
@@ -971,6 +971,9 @@ print_value_quoted(const char *s)
                 if (ctype(*p, C_QUOTE))
         if (!*p) {
+               /* handle zero-length value */
+               if (p == s)
+                       s = "''";
                 shprintf("%s", s);

...but I'm find with the original diff too.

FWIW, your way seems fine to me as well.


- M.

Reply via email to