]> git.ipfire.org Git - thirdparty/bash.git/blobdiff - builtins/setattr.def
bash-4.4 rc1 release
[thirdparty/bash.git] / builtins / setattr.def
index 178a0b336b6db81dfd0b58d61050d76c371ab095..9e9309ffe226a84f77d6742a632153b6a131801d 100644 (file)
@@ -1,7 +1,7 @@
 This file is setattr.def, from which is created setattr.c.
 It implements the builtins "export" and "readonly", in Bash.
 
-Copyright (C) 1987-2014 Free Software Foundation, Inc.
+Copyright (C) 1987-2015 Free Software Foundation, Inc.
 
 This file is part of GNU Bash, the Bourne Again SHell.
 
@@ -134,6 +134,8 @@ set_or_show_attributes (list, attribute, nodefs)
 #if defined (ARRAY_VARS)
   WORD_LIST *nlist, *tlist;
   WORD_DESC *w;
+  char optw[8];
+  int opti;
 #endif
 
   functions_only = arrays_only = assoc_only = 0;
@@ -160,6 +162,7 @@ set_or_show_attributes (list, attribute, nodefs)
 #endif
          case 'p':
            break;
+         CASE_HELPOPT;
          default:
            builtin_usage ();
            return (EX_USAGE);
@@ -237,8 +240,24 @@ set_or_show_attributes (list, attribute, nodefs)
                {
                  tlist = list->next;
                  list->next = (WORD_LIST *)NULL;
-                 w = arrays_only ? make_word ("-ra") : make_word ("-rA");
+                 /* Add -g to avoid readonly/export creating local variables:
+                    only local/declare/typeset create local variables */
+                 opti = 0;
+                 optw[opti++] = '-';
+                 optw[opti++] = 'g';
+                 if (attribute & att_readonly)
+                   optw[opti++] = 'r';
+                 if (attribute & att_exported)
+                   optw[opti++] = 'x';
+                 if (arrays_only)
+                   optw[opti++] = 'a';
+                 else
+                   optw[opti++] = 'A';
+                 optw[opti] = '\0';
+
+                 w = make_word (optw);
                  nlist = make_word_list (w, list);
+
                  opt = declare_builtin (nlist);
                  if (opt != EXECUTION_SUCCESS)
                    assign_error++;