/bin/ksh ksh(1) typeset -p output weirdness

Previous Topic Next Topic
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

/bin/ksh ksh(1) typeset -p output weirdness

>Synopsis: ksh(pd) `typeset -p` lists all variables as readonly
>Category: user
        System      : OpenBSD 6.2
        Details     : OpenBSD 6.2 (GENERIC.MP) #5: Fri Feb  2 23:02:19 CET 2018
                         [hidden email]:/usr/src/sys/arch/amd64/compile/GENERIC.MP

        Architecture: OpenBSD.amd64
        Machine     : amd64
        The ksh(1) man page describes the `-p` option as being equivalent
        to the default of no parameters, but actually using the `-p` option
        results in a very different output with the somewhat bizarre
        behavior of prefixing each variable with "readonly "
        From within ksh issue the command `typeset -p`
        Within the source code (src/bin/ksh/c_ksh.c), the offending lines
        test the pflag variable and if set test the variable `flag` instead
        of testing `vp->flag` and further assume that the a shell variable
        can only be EXPORT or RDONLY.

        The following patch will fix that behavior but it still won't be
        consistent with the manual. And the default printout and the `-p`
        format of ksh93 is the reverse of what the fix will do, though that
        seems to be what the code intended to do anyway.

        Possibly a better fix would be to remove the special handling of
        the `-p` format.

Index: c_ksh.c
RCS file: /home/tw/src/sys/openbsd-cvs/src/bin/ksh/c_ksh.c,v
retrieving revision 1.58
diff -u -p -r1.58 c_ksh.c
--- c_ksh.c 16 Jan 2018 22:52:32 -0000 1.58
+++ c_ksh.c 7 Feb 2018 23:09:06 -0000
@@ -790,10 +790,12 @@ c_typeset(char **wp)
     if (vp->flag&ARRAY)
  } else {
- if (pflag)
- shprintf("%s ",
-    (flag & EXPORT) ?
-    "export" : "readonly");
+ if (pflag) {
+ if (vp->flag & EXPORT)
+ shprintf("export ");
+ else if ((vp->flag&RDONLY))
+ shprintf("readonly ");
+ }
  if ((vp->flag&ARRAY) && any_set)
     vp->name, vp->index);