summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog3
-rw-r--r--Src/params.c15
-rw-r--r--Test/B02typeset.ztst6
3 files changed, 20 insertions, 4 deletions
diff --git a/ChangeLog b/ChangeLog
index a1544f4c4..66bff0ecc 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,8 @@
 2015-05-07  Peter Stephenson  <p.stephenson@samsung.com>
 
+	* 35054: Src/params.c, Test/B02typeset.ztst: "readonly -p"
+	displays unset readonly variables with POSIXBUILTINS.
+
 	* Eric Cook: 35052: Completion/BSD/Command/_bsdconfig,
 	Completion/BSD/Command/_bsdinstall,
 	Completion/BSD/Command/_jexec, Completion/BSD/Command/_jls:
diff --git a/Src/params.c b/Src/params.c
index d53b6ca7e..9eab51a34 100644
--- a/Src/params.c
+++ b/Src/params.c
@@ -5039,8 +5039,19 @@ printparamnode(HashNode hn, int printflags)
     Param p = (Param) hn;
     char *t, **u;
 
-    if (p->node.flags & PM_UNSET)
-	return;
+    if (p->node.flags & PM_UNSET) {
+	if (isset(POSIXBUILTINS) && (p->node.flags & PM_READONLY) &&
+	    (printflags & PRINT_TYPESET))
+	{
+	    /*
+	     * Special POSIX rules: show the parameter as readonly
+	     * even though it's unset, but with no value.
+	     */
+	    printflags |= PRINT_NAMEONLY;
+	}
+	else
+	    return;
+    }
 
     if (printflags & PRINT_TYPESET)
 	printf("typeset ");
diff --git a/Test/B02typeset.ztst b/Test/B02typeset.ztst
index f4fb8ecb9..2edbb0b5e 100644
--- a/Test/B02typeset.ztst
+++ b/Test/B02typeset.ztst
@@ -475,13 +475,15 @@
    print ${+pbro} >&2
    (typeset pbro=3)
    (pbro=4)
+   readonly -p | grep pbro >&2  # shows up as "readonly" although unset
    typeset -r pbro        # idempotent (no error)...
    print ${+pbro} >&2     # ...so still readonly...
    typeset +r pbro        # ...can't turn it off
  )
-1:Readonly with POSIX_BUILTINS
+1:readonly with POSIX_BUILTINS
 ?0
 ?(eval):5: read-only variable: pbro
 ?(eval):6: read-only variable: pbro
+?typeset -r pbro
 ?0
-?(eval):9: read-only variable: pbro
+?(eval):10: read-only variable: pbro