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:

: morgaine; ksh -c 'alias foo=""; alias -p; export foo=; set; export -p' | grep 
foo
alias foo=
foo=
export foo=
: morgaine; obj/ksh -c 'alias foo=""; alias -p; export foo=; set; export -p' | 
grep foo
alias foo=''
foo=''
export foo=''
: morgaine;

Are there any regress tests affected by this?


> --- misc.c    9 Apr 2018 17:53:36 -0000       1.70
> +++ misc.c    14 Apr 2018 22:44:39 -0000
> @@ -966,6 +966,12 @@ print_value_quoted(const char *s)
>       const char *p;
>       int inquote = 0;
> 
> +     /* Check for empty */
> +     if (!*p) {
> +             shprintf("''");
> +             return;
> +     }
> +

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))
                        break;
        if (!*p) {
+               /* handle zero-length value */
+               if (p == s)
+                       s = "''";
                shprintf("%s", s);
                return;
        }


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


Philip

Reply via email to