| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  | This file is setattr.def, from which is created setattr.c. | 
					
						
							|  |  |  | It implements the builtins "export" and "readonly", in Bash. | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-09-15 16:59:08 -04:00
										 |  |  | Copyright (C) 1987-2015 Free Software Foundation, Inc. | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | This file is part of GNU Bash, the Bourne Again SHell. | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-01-12 13:36:28 +00:00
										 |  |  | Bash is free software: you can redistribute it and/or modify | 
					
						
							|  |  |  | it under the terms of the GNU General Public License as published by | 
					
						
							|  |  |  | the Free Software Foundation, either version 3 of the License, or | 
					
						
							|  |  |  | (at your option) any later version. | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-01-12 13:36:28 +00:00
										 |  |  | Bash is distributed in the hope that it will be useful, | 
					
						
							|  |  |  | but WITHOUT ANY WARRANTY; without even the implied warranty of | 
					
						
							|  |  |  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
					
						
							|  |  |  | GNU General Public License for more details. | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-01-12 13:36:28 +00:00
										 |  |  | You should have received a copy of the GNU General Public License | 
					
						
							|  |  |  | along with Bash.  If not, see <http://www.gnu.org/licenses/>. | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | $PRODUCES setattr.c | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  | #include <config.h> | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #if defined (HAVE_UNISTD_H) | 
					
						
							| 
									
										
										
										
											1998-04-17 19:52:44 +00:00
										 |  |  | #  ifdef _MINIX | 
					
						
							|  |  |  | #    include <sys/types.h> | 
					
						
							|  |  |  | #  endif | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  | #  include <unistd.h> | 
					
						
							|  |  |  | #endif | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <stdio.h> | 
					
						
							|  |  |  | #include "../bashansi.h" | 
					
						
							| 
									
										
										
										
											2004-07-27 13:29:18 +00:00
										 |  |  | #include "../bashintl.h" | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  | #include "../shell.h" | 
					
						
							| 
									
										
										
										
											2016-09-15 16:59:08 -04:00
										 |  |  | #include "../flags.h" | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  | #include "common.h" | 
					
						
							|  |  |  | #include "bashgetopt.h" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1997-06-05 14:59:13 +00:00
										 |  |  | extern int posixly_correct; | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  | extern int array_needs_making; | 
					
						
							|  |  |  | extern char *this_command_name; | 
					
						
							| 
									
										
										
										
											2001-11-13 17:56:06 +00:00
										 |  |  | extern sh_builtin_func_t *this_shell_builtin; | 
					
						
							| 
									
										
										
										
											1997-06-05 14:59:13 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | #ifdef ARRAY_VARS | 
					
						
							| 
									
										
										
										
											2002-07-17 14:10:11 +00:00
										 |  |  | extern int declare_builtin __P((WORD_LIST *)); | 
					
						
							| 
									
										
										
										
											1997-06-05 14:59:13 +00:00
										 |  |  | #endif | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #define READONLY_OR_EXPORT \ | 
					
						
							|  |  |  |   (this_shell_builtin == readonly_builtin || this_shell_builtin == export_builtin) | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | $BUILTIN export | 
					
						
							|  |  |  | $FUNCTION export_builtin | 
					
						
							| 
									
										
										
										
											2009-01-12 13:36:28 +00:00
										 |  |  | $SHORT_DOC export [-fn] [name[=value] ...] or export -p | 
					
						
							|  |  |  | Set export attribute for shell variables. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Marks each NAME for automatic export to the environment of subsequently | 
					
						
							|  |  |  | executed commands.  If VALUE is supplied, assign VALUE before exporting. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Options: | 
					
						
							|  |  |  |   -f	refer to shell functions | 
					
						
							|  |  |  |   -n	remove the export property from each NAME | 
					
						
							|  |  |  |   -p	display a list of all exported variables and functions | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | An argument of `--' disables further option processing. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Exit Status: | 
					
						
							|  |  |  | Returns success unless an invalid option is given or NAME is invalid. | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  | $END | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* For each variable name in LIST, make that variable appear in the | 
					
						
							|  |  |  |    environment passed to simple commands.  If there is no LIST, then | 
					
						
							|  |  |  |    print all such variables.  An argument of `-n' says to remove the | 
					
						
							|  |  |  |    exported attribute from variables named in LIST.  An argument of | 
					
						
							|  |  |  |   -f indicates that the names present in LIST refer to functions. */ | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  | int | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  | export_builtin (list) | 
					
						
							|  |  |  |      register WORD_LIST *list; | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  |   return (set_or_show_attributes (list, att_exported, 0)); | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | $BUILTIN readonly | 
					
						
							|  |  |  | $FUNCTION readonly_builtin | 
					
						
							| 
									
										
										
										
											2011-11-22 19:11:26 -05:00
										 |  |  | $SHORT_DOC readonly [-aAf] [name[=value] ...] or readonly -p | 
					
						
							| 
									
										
										
										
											2009-01-12 13:36:28 +00:00
										 |  |  | Mark shell variables as unchangeable. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Mark each NAME as read-only; the values of these NAMEs may not be | 
					
						
							|  |  |  | changed by subsequent assignment.  If VALUE is supplied, assign VALUE | 
					
						
							|  |  |  | before marking as read-only. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Options: | 
					
						
							|  |  |  |   -a	refer to indexed array variables | 
					
						
							|  |  |  |   -A	refer to associative array variables | 
					
						
							|  |  |  |   -f	refer to shell functions | 
					
						
							| 
									
										
										
										
											2016-09-15 16:59:08 -04:00
										 |  |  |   -p	display a list of all readonly variables or functions, | 
					
						
							|  |  |  | 		depending on whether or not the -f option is given | 
					
						
							| 
									
										
										
										
											2009-01-12 13:36:28 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | An argument of `--' disables further option processing. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Exit Status: | 
					
						
							|  |  |  | Returns success unless an invalid option is given or NAME is invalid. | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  | $END | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* For each variable name in LIST, make that variable readonly.  Given an | 
					
						
							|  |  |  |    empty LIST, print out all existing readonly variables. */ | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  | int | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  | readonly_builtin (list) | 
					
						
							|  |  |  |      register WORD_LIST *list; | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  |   return (set_or_show_attributes (list, att_readonly, 0)); | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-07-17 14:10:11 +00:00
										 |  |  | #if defined (ARRAY_VARS) | 
					
						
							| 
									
										
										
										
											2009-01-12 13:36:28 +00:00
										 |  |  | #  define ATTROPTS	"aAfnp" | 
					
						
							| 
									
										
										
										
											2002-07-17 14:10:11 +00:00
										 |  |  | #else | 
					
						
							|  |  |  | #  define ATTROPTS	"fnp" | 
					
						
							|  |  |  | #endif | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  | /* For each variable name in LIST, make that variable have the specified | 
					
						
							|  |  |  |    ATTRIBUTE.  An arg of `-n' says to remove the attribute from the the | 
					
						
							| 
									
										
										
										
											2004-07-27 13:29:18 +00:00
										 |  |  |    remaining names in LIST (doesn't work for readonly). */ | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  | int | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  | set_or_show_attributes (list, attribute, nodefs) | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  |      register WORD_LIST *list; | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  |      int attribute, nodefs; | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  | { | 
					
						
							|  |  |  |   register SHELL_VAR *var; | 
					
						
							| 
									
										
										
										
											2009-01-12 13:36:28 +00:00
										 |  |  |   int assign, undo, any_failed, assign_error, opt; | 
					
						
							|  |  |  |   int functions_only, arrays_only, assoc_only; | 
					
						
							| 
									
										
										
										
											2005-12-07 14:08:12 +00:00
										 |  |  |   int aflags; | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  |   char *name; | 
					
						
							| 
									
										
										
										
											1997-06-05 14:59:13 +00:00
										 |  |  | #if defined (ARRAY_VARS) | 
					
						
							|  |  |  |   WORD_LIST *nlist, *tlist; | 
					
						
							|  |  |  |   WORD_DESC *w; | 
					
						
							| 
									
										
										
										
											2016-09-15 16:59:08 -04:00
										 |  |  |   char optw[8]; | 
					
						
							|  |  |  |   int opti; | 
					
						
							| 
									
										
										
										
											1997-06-05 14:59:13 +00:00
										 |  |  | #endif | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-01-12 13:36:28 +00:00
										 |  |  |   functions_only = arrays_only = assoc_only = 0; | 
					
						
							|  |  |  |   undo = any_failed = assign_error = 0; | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  |   /* Read arguments from the front of the list. */ | 
					
						
							|  |  |  |   reset_internal_getopt (); | 
					
						
							| 
									
										
										
										
											2002-07-17 14:10:11 +00:00
										 |  |  |   while ((opt = internal_getopt (list, ATTROPTS)) != -1) | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  |     { | 
					
						
							|  |  |  |       switch (opt) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 	  case 'n': | 
					
						
							|  |  |  | 	    undo = 1; | 
					
						
							|  |  |  | 	    break; | 
					
						
							|  |  |  | 	  case 'f': | 
					
						
							|  |  |  | 	    functions_only = 1; | 
					
						
							|  |  |  | 	    break; | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  | #if defined (ARRAY_VARS) | 
					
						
							|  |  |  | 	  case 'a': | 
					
						
							| 
									
										
										
										
											2009-01-12 13:36:28 +00:00
										 |  |  | 	    arrays_only = 1; | 
					
						
							|  |  |  | 	    break; | 
					
						
							|  |  |  | 	  case 'A': | 
					
						
							|  |  |  | 	    assoc_only = 1; | 
					
						
							|  |  |  | 	    break; | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  | #endif | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  | 	  case 'p': | 
					
						
							|  |  |  | 	    break; | 
					
						
							| 
									
										
										
										
											2016-09-15 16:59:08 -04:00
										 |  |  | 	  CASE_HELPOPT; | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  | 	  default: | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  | 	    builtin_usage (); | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  | 	    return (EX_USAGE); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   list = loptend; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   if (list) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |       if (attribute & att_exported) | 
					
						
							|  |  |  | 	array_needs_making = 1; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  |       /* Cannot undo readonly status, silently disallowed. */ | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  |       if (undo && (attribute & att_readonly)) | 
					
						
							|  |  |  | 	attribute &= ~att_readonly; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       while (list) | 
					
						
							|  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  | 	  name = list->word->word; | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  | 	  if (functions_only)		/* xxx -f name */ | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  | 	    { | 
					
						
							|  |  |  | 	      var = find_function (name); | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  | 	      if (var == 0) | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2004-07-27 13:29:18 +00:00
										 |  |  | 		  builtin_error (_("%s: not a function"), name); | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  | 		  any_failed++; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2016-09-15 16:59:08 -04:00
										 |  |  | 	      else if ((attribute & att_exported) && undo == 0 && exportable_function_name (name) == 0) | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 		  builtin_error (_("%s: cannot export"), name); | 
					
						
							|  |  |  | 		  any_failed++; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  | 	      else | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  | 		SETVARATTR (var, attribute, undo); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  | 	      list = list->next; | 
					
						
							|  |  |  | 	      continue; | 
					
						
							|  |  |  | 	    } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  | 	  /* xxx [-np] name[=value] */ | 
					
						
							| 
									
										
										
										
											2004-07-27 13:29:18 +00:00
										 |  |  | 	  assign = assignment (name, 0); | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-12-07 14:08:12 +00:00
										 |  |  | 	  aflags = 0; | 
					
						
							| 
									
										
										
										
											2001-04-06 19:14:31 +00:00
										 |  |  | 	  if (assign) | 
					
						
							| 
									
										
										
										
											2005-12-07 14:08:12 +00:00
										 |  |  | 	    { | 
					
						
							|  |  |  | 	      name[assign] = '\0'; | 
					
						
							|  |  |  | 	      if (name[assign - 1] == '+') | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 		  aflags |= ASS_APPEND; | 
					
						
							|  |  |  | 		  name[assign - 1] = '\0'; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	    } | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  | 	  if (legal_identifier (name) == 0) | 
					
						
							|  |  |  | 	    { | 
					
						
							| 
									
										
										
										
											2002-07-17 14:10:11 +00:00
										 |  |  | 	      sh_invalidid (name); | 
					
						
							| 
									
										
										
										
											1997-06-05 14:59:13 +00:00
										 |  |  | 	      if (assign) | 
					
						
							|  |  |  | 		assign_error++; | 
					
						
							|  |  |  | 	      else | 
					
						
							|  |  |  | 		any_failed++; | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  | 	      list = list->next; | 
					
						
							|  |  |  | 	      continue; | 
					
						
							|  |  |  | 	    } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  | 	  if (assign)	/* xxx [-np] name=value */ | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  | 	    { | 
					
						
							|  |  |  | 	      name[assign] = '='; | 
					
						
							| 
									
										
										
										
											2005-12-07 14:08:12 +00:00
										 |  |  | 	      if (aflags & ASS_APPEND) | 
					
						
							|  |  |  | 		name[assign - 1] = '+'; | 
					
						
							| 
									
										
										
										
											1997-06-05 14:59:13 +00:00
										 |  |  | #if defined (ARRAY_VARS) | 
					
						
							|  |  |  | 	      /* Let's try something here.  Turn readonly -a xxx=yyy into | 
					
						
							|  |  |  | 		 declare -ra xxx=yyy and see what that gets us. */ | 
					
						
							| 
									
										
										
										
											2009-01-12 13:36:28 +00:00
										 |  |  | 	      if (arrays_only || assoc_only) | 
					
						
							| 
									
										
										
										
											1997-06-05 14:59:13 +00:00
										 |  |  | 		{ | 
					
						
							|  |  |  | 		  tlist = list->next; | 
					
						
							|  |  |  | 		  list->next = (WORD_LIST *)NULL; | 
					
						
							| 
									
										
										
										
											2016-09-15 16:59:08 -04:00
										 |  |  | 		  /* 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); | 
					
						
							| 
									
										
										
										
											1997-06-05 14:59:13 +00:00
										 |  |  | 		  nlist = make_word_list (w, list); | 
					
						
							| 
									
										
										
										
											2016-09-15 16:59:08 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											1997-06-05 14:59:13 +00:00
										 |  |  | 		  opt = declare_builtin (nlist); | 
					
						
							|  |  |  | 		  if (opt != EXECUTION_SUCCESS) | 
					
						
							|  |  |  | 		    assign_error++; | 
					
						
							|  |  |  | 		  list->next = tlist; | 
					
						
							|  |  |  | 		  dispose_word (w); | 
					
						
							|  |  |  | 		  free (nlist); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	      else | 
					
						
							|  |  |  | #endif | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  | 	      /* This word has already been expanded once with command | 
					
						
							|  |  |  | 		 and parameter expansion.  Call do_assignment_no_expand (), | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  | 		 which does not do command or parameter substitution.  If | 
					
						
							|  |  |  | 		 the assignment is not performed correctly, flag an error. */ | 
					
						
							|  |  |  | 	      if (do_assignment_no_expand (name) == 0) | 
					
						
							|  |  |  | 		assign_error++; | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  | 	      name[assign] = '\0'; | 
					
						
							| 
									
										
										
										
											2005-12-07 14:08:12 +00:00
										 |  |  | 	      if (aflags & ASS_APPEND) | 
					
						
							|  |  |  | 		name[assign - 1] = '\0'; | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  | 	    } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  | 	  set_var_attribute (name, attribute, undo); | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  | 	  list = list->next; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   else | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |       SHELL_VAR **variable_list; | 
					
						
							|  |  |  |       register int i; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       if ((attribute & att_function) || functions_only) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 	  variable_list = all_shell_functions (); | 
					
						
							|  |  |  | 	  if (attribute != att_function) | 
					
						
							|  |  |  | 	    attribute &= ~att_function;	/* so declare -xf works, for example */ | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  |       else | 
					
						
							|  |  |  | 	variable_list = all_shell_variables (); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  | #if defined (ARRAY_VARS) | 
					
						
							|  |  |  |       if (attribute & att_array) | 
					
						
							| 
									
										
										
										
											2001-04-06 19:14:31 +00:00
										 |  |  | 	{ | 
					
						
							|  |  |  | 	  arrays_only++; | 
					
						
							|  |  |  | 	  if (attribute != att_array) | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  | 	    attribute &= ~att_array; | 
					
						
							| 
									
										
										
										
											2001-04-06 19:14:31 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2009-01-12 13:36:28 +00:00
										 |  |  |       else if (attribute & att_assoc) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 	  assoc_only++; | 
					
						
							|  |  |  | 	  if (attribute != att_assoc) | 
					
						
							|  |  |  | 	    attribute &= ~att_assoc; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  | #endif | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  |       if (variable_list) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 	  for (i = 0; var = variable_list[i]; i++) | 
					
						
							|  |  |  | 	    { | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  | #if defined (ARRAY_VARS) | 
					
						
							|  |  |  | 	      if (arrays_only && array_p (var) == 0) | 
					
						
							| 
									
										
										
										
											2001-04-06 19:14:31 +00:00
										 |  |  | 		continue; | 
					
						
							| 
									
										
										
										
											2009-01-12 13:36:28 +00:00
										 |  |  | 	      else if (assoc_only && assoc_p (var) == 0) | 
					
						
							|  |  |  | 		continue; | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  | #endif | 
					
						
							| 
									
										
										
										
											2016-09-15 16:59:08 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	      /* If we imported a variable that's not a valid identifier, don't | 
					
						
							|  |  |  | 		 show it in any lists. */ | 
					
						
							|  |  |  | 	      if ((var->attributes & (att_invisible|att_imported)) == (att_invisible|att_imported)) | 
					
						
							|  |  |  | 		continue; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-11-13 17:56:06 +00:00
										 |  |  | 	      if ((var->attributes & attribute)) | 
					
						
							| 
									
										
										
										
											2009-01-12 13:36:28 +00:00
										 |  |  | 		{ | 
					
						
							|  |  |  | 		  show_var_attributes (var, READONLY_OR_EXPORT, nodefs); | 
					
						
							|  |  |  | 		  if (any_failed = sh_chkwrite (any_failed)) | 
					
						
							|  |  |  | 		    break; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  | 	    } | 
					
						
							|  |  |  | 	  free (variable_list); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   return (assign_error ? EX_BADASSIGN | 
					
						
							|  |  |  | 		       : ((any_failed == 0) ? EXECUTION_SUCCESS | 
					
						
							|  |  |  |   					    : EXECUTION_FAILURE)); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-01-12 13:36:28 +00:00
										 |  |  | /* Show all variable variables (v == 1) or functions (v == 0) with | 
					
						
							|  |  |  |    attributes. */ | 
					
						
							|  |  |  | int | 
					
						
							|  |  |  | show_all_var_attributes (v, nodefs) | 
					
						
							|  |  |  |      int v, nodefs; | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   SHELL_VAR **variable_list, *var; | 
					
						
							|  |  |  |   int any_failed; | 
					
						
							|  |  |  |   register int i; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   variable_list = v ? all_shell_variables () : all_shell_functions (); | 
					
						
							|  |  |  |   if (variable_list == 0)   | 
					
						
							|  |  |  |     return (EXECUTION_SUCCESS); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   for (i = any_failed = 0; var = variable_list[i]; i++) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |       show_var_attributes (var, READONLY_OR_EXPORT, nodefs); | 
					
						
							|  |  |  |       if (any_failed = sh_chkwrite (any_failed)) | 
					
						
							|  |  |  |         break; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   free (variable_list); | 
					
						
							|  |  |  |   return (any_failed == 0 ? EXECUTION_SUCCESS : EXECUTION_FAILURE); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  | int | 
					
						
							| 
									
										
										
										
											2016-09-15 16:59:08 -04:00
										 |  |  | var_attribute_string (var, pattr, flags) | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  |      SHELL_VAR *var; | 
					
						
							| 
									
										
										
										
											2016-09-15 16:59:08 -04:00
										 |  |  |      int pattr; | 
					
						
							|  |  |  |      char *flags;	/* filled in with attributes */ | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  | { | 
					
						
							|  |  |  |   int i; | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  |   i = 0; | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											1997-06-05 14:59:13 +00:00
										 |  |  |   /* pattr == 0 means we are called from `declare'. */ | 
					
						
							|  |  |  |   if (pattr == 0 || posixly_correct == 0) | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  | #if defined (ARRAY_VARS) | 
					
						
							| 
									
										
										
										
											1997-06-05 14:59:13 +00:00
										 |  |  |       if (array_p (var)) | 
					
						
							|  |  |  | 	flags[i++] = 'a'; | 
					
						
							| 
									
										
										
										
											2009-01-12 13:36:28 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |       if (assoc_p (var)) | 
					
						
							|  |  |  | 	flags[i++] = 'A'; | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  | #endif | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											1997-06-05 14:59:13 +00:00
										 |  |  |       if (function_p (var)) | 
					
						
							| 
									
										
										
										
											2001-04-06 19:14:31 +00:00
										 |  |  | 	flags[i++] = 'f'; | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											1997-06-05 14:59:13 +00:00
										 |  |  |       if (integer_p (var)) | 
					
						
							| 
									
										
										
										
											2001-04-06 19:14:31 +00:00
										 |  |  | 	flags[i++] = 'i'; | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-26 09:36:43 -05:00
										 |  |  |       if (nameref_p (var)) | 
					
						
							|  |  |  | 	flags[i++] = 'n'; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1997-06-05 14:59:13 +00:00
										 |  |  |       if (readonly_p (var)) | 
					
						
							| 
									
										
										
										
											2001-04-06 19:14:31 +00:00
										 |  |  | 	flags[i++] = 'r'; | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-07-17 14:10:11 +00:00
										 |  |  |       if (trace_p (var)) | 
					
						
							|  |  |  | 	flags[i++] = 't'; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1997-06-05 14:59:13 +00:00
										 |  |  |       if (exported_p (var)) | 
					
						
							| 
									
										
										
										
											2001-04-06 19:14:31 +00:00
										 |  |  | 	flags[i++] = 'x'; | 
					
						
							| 
									
										
										
										
											2009-01-12 13:36:28 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |       if (capcase_p (var)) | 
					
						
							|  |  |  | 	flags[i++] = 'c'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       if (lowercase_p (var)) | 
					
						
							|  |  |  | 	flags[i++] = 'l'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       if (uppercase_p (var)) | 
					
						
							|  |  |  | 	flags[i++] = 'u'; | 
					
						
							| 
									
										
										
										
											1997-06-05 14:59:13 +00:00
										 |  |  |     } | 
					
						
							|  |  |  |   else | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  | #if defined (ARRAY_VARS) | 
					
						
							|  |  |  |       if (array_p (var)) | 
					
						
							|  |  |  | 	flags[i++] = 'a'; | 
					
						
							| 
									
										
										
										
											2009-01-12 13:36:28 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |       if (assoc_p (var)) | 
					
						
							|  |  |  | 	flags[i++] = 'A'; | 
					
						
							| 
									
										
										
										
											1997-06-05 14:59:13 +00:00
										 |  |  | #endif | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       if (function_p (var)) | 
					
						
							| 
									
										
										
										
											2001-04-06 19:14:31 +00:00
										 |  |  | 	flags[i++] = 'f'; | 
					
						
							| 
									
										
										
										
											1997-06-05 14:59:13 +00:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  |   flags[i] = '\0'; | 
					
						
							| 
									
										
										
										
											2016-09-15 16:59:08 -04:00
										 |  |  |   return i; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* Show the attributes for shell variable VAR.  If NODEFS is non-zero, | 
					
						
							|  |  |  |    don't show function definitions along with the name.  If PATTR is | 
					
						
							|  |  |  |    non-zero, it indicates we're being called from `export' or `readonly'. | 
					
						
							|  |  |  |    In POSIX mode, this prints the name of the calling builtin (`export' | 
					
						
							|  |  |  |    or `readonly') instead of `declare', and doesn't print function defs | 
					
						
							|  |  |  |    when called by `export' or `readonly'. */ | 
					
						
							|  |  |  | int | 
					
						
							|  |  |  | show_var_attributes (var, pattr, nodefs) | 
					
						
							|  |  |  |      SHELL_VAR *var; | 
					
						
							|  |  |  |      int pattr, nodefs; | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   char flags[MAX_ATTRIBUTES], *x; | 
					
						
							|  |  |  |   int i; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   i = var_attribute_string (var, pattr, flags); | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-07-17 14:10:11 +00:00
										 |  |  |   /* If we're printing functions with definitions, print the function def | 
					
						
							|  |  |  |      first, then the attributes, instead of printing output that can't be | 
					
						
							|  |  |  |      reused as input to recreate the current state. */ | 
					
						
							|  |  |  |   if (function_p (var) && nodefs == 0 && (pattr == 0 || posixly_correct == 0)) | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2009-01-12 13:36:28 +00:00
										 |  |  |       printf ("%s\n", named_function_string (var->name, function_cell (var), FUNC_MULTILINE|FUNC_EXTERNAL)); | 
					
						
							| 
									
										
										
										
											2002-07-17 14:10:11 +00:00
										 |  |  |       nodefs++; | 
					
						
							|  |  |  |       if (pattr == 0 && i == 1 && flags[0] == 'f') | 
					
						
							|  |  |  | 	return 0;		/* don't print `declare -f name' */ | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1997-06-05 14:59:13 +00:00
										 |  |  |   if (pattr == 0 || posixly_correct == 0) | 
					
						
							|  |  |  |     printf ("declare -%s ", i ? flags : "-"); | 
					
						
							|  |  |  |   else if (i) | 
					
						
							|  |  |  |     printf ("%s -%s ", this_command_name, flags); | 
					
						
							|  |  |  |   else | 
					
						
							|  |  |  |     printf ("%s ", this_command_name); | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | #if defined (ARRAY_VARS) | 
					
						
							| 
									
										
										
										
											2016-09-15 16:59:08 -04:00
										 |  |  |   if (invisible_p (var) && (array_p (var) || assoc_p (var))) | 
					
						
							|  |  |  |     printf ("%s\n", var->name); | 
					
						
							|  |  |  |   else if (array_p (var)) | 
					
						
							|  |  |  |     print_array_assignment (var, 0); | 
					
						
							| 
									
										
										
										
											2009-01-12 13:36:28 +00:00
										 |  |  |   else if (assoc_p (var)) | 
					
						
							| 
									
										
										
										
											2016-09-15 16:59:08 -04:00
										 |  |  |     print_assoc_assignment (var, 0); | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  |   else | 
					
						
							|  |  |  | #endif | 
					
						
							| 
									
										
										
										
											2002-07-17 14:10:11 +00:00
										 |  |  |   /* force `readonly' and `export' to not print out function definitions | 
					
						
							| 
									
										
										
										
											1997-06-05 14:59:13 +00:00
										 |  |  |      when in POSIX mode. */ | 
					
						
							|  |  |  |   if (nodefs || (function_p (var) && pattr != 0 && posixly_correct)) | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  |     printf ("%s\n", var->name); | 
					
						
							|  |  |  |   else if (function_p (var)) | 
					
						
							| 
									
										
										
										
											2009-01-12 13:36:28 +00:00
										 |  |  |     printf ("%s\n", named_function_string (var->name, function_cell (var), FUNC_MULTILINE|FUNC_EXTERNAL)); | 
					
						
							| 
									
										
										
										
											2011-11-22 19:11:26 -05:00
										 |  |  |   else if (invisible_p (var) || var_isset (var) == 0) | 
					
						
							| 
									
										
										
										
											2001-11-13 17:56:06 +00:00
										 |  |  |     printf ("%s\n", var->name); | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  |   else | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2011-11-22 19:11:26 -05:00
										 |  |  |       x = sh_double_quote (value_cell (var)); | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  |       printf ("%s=%s\n", var->name, x); | 
					
						
							|  |  |  |       free (x); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   return (0); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | int | 
					
						
							|  |  |  | show_name_attributes (name, nodefs) | 
					
						
							|  |  |  |      char *name; | 
					
						
							|  |  |  |      int nodefs; | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   SHELL_VAR *var; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-26 09:36:43 -05:00
										 |  |  | #if 0 | 
					
						
							|  |  |  |   var = find_variable_tempenv (name); | 
					
						
							|  |  |  | #else | 
					
						
							|  |  |  |   var = find_variable_noref (name); | 
					
						
							|  |  |  | #endif | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-09-15 16:59:08 -04:00
										 |  |  |   if (var /* && invisible_p (var) == 0 */)	/* XXX bash-4.4/bash-5.0 */ | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											1997-06-05 14:59:13 +00:00
										 |  |  |       show_var_attributes (var, READONLY_OR_EXPORT, nodefs); | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  |       return (0); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   else | 
					
						
							|  |  |  |     return (1); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-26 09:36:43 -05:00
										 |  |  | int | 
					
						
							|  |  |  | show_func_attributes (name, nodefs) | 
					
						
							|  |  |  |      char *name; | 
					
						
							|  |  |  |      int nodefs; | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   SHELL_VAR *var; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   var = find_function (name); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   if (var) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |       show_var_attributes (var, READONLY_OR_EXPORT, nodefs); | 
					
						
							|  |  |  |       return (0); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   else | 
					
						
							|  |  |  |     return (1); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  | void | 
					
						
							|  |  |  | set_var_attribute (name, attribute, undo) | 
					
						
							|  |  |  |      char *name; | 
					
						
							|  |  |  |      int attribute, undo; | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2016-09-15 16:59:08 -04:00
										 |  |  |   SHELL_VAR *var, *tv, *v, *refvar; | 
					
						
							|  |  |  |   char *tvalue, *refname; | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |   if (undo) | 
					
						
							|  |  |  |     var = find_variable (name); | 
					
						
							|  |  |  |   else | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2002-07-17 14:10:11 +00:00
										 |  |  |       tv = find_tempenv_variable (name); | 
					
						
							|  |  |  |       /* XXX -- need to handle case where tv is a temp variable in a | 
					
						
							|  |  |  | 	 function-scope context, since function_env has been merged into | 
					
						
							|  |  |  | 	 the local variables table. */ | 
					
						
							|  |  |  |       if (tv && tempvar_p (tv)) | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2002-07-17 14:10:11 +00:00
										 |  |  | 	  tvalue = var_isset (tv) ? savestring (value_cell (tv)) : savestring (""); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-12-07 14:08:12 +00:00
										 |  |  | 	  var = bind_variable (tv->name, tvalue, 0); | 
					
						
							| 
									
										
										
										
											2016-09-15 16:59:08 -04:00
										 |  |  | 	  if (var == 0) | 
					
						
							|  |  |  | 	    { | 
					
						
							|  |  |  | 	      free (tvalue); | 
					
						
							|  |  |  | 	      return;		/* XXX - no error message here */ | 
					
						
							|  |  |  | 	    } | 
					
						
							| 
									
										
										
										
											2002-07-17 14:10:11 +00:00
										 |  |  | 	  var->attributes |= tv->attributes & ~att_tempvar; | 
					
						
							| 
									
										
										
										
											2014-02-26 09:36:43 -05:00
										 |  |  | 	  /* This avoids an error message when propagating a read-only var | 
					
						
							|  |  |  | 	     later on. */ | 
					
						
							|  |  |  | 	  if (var->context == 0 && (attribute & att_readonly)) | 
					
						
							|  |  |  | 	    { | 
					
						
							|  |  |  | 	      /* Don't bother to set the `propagate to the global variables | 
					
						
							|  |  |  | 		 table' flag if we've just bound the variable in that table */ | 
					
						
							|  |  |  | 	      v = find_global_variable (tv->name); | 
					
						
							|  |  |  | 	      if (v != var) | 
					
						
							|  |  |  | 		VSETATTR (tv, att_propagate); | 
					
						
							|  |  |  | 	    } | 
					
						
							|  |  |  | 	  else | 
					
						
							|  |  |  | 	    VSETATTR (tv, att_propagate); | 
					
						
							| 
									
										
										
										
											2002-07-17 14:10:11 +00:00
										 |  |  | 	  if (var->context != 0) | 
					
						
							|  |  |  | 	    VSETATTR (var, att_propagate); | 
					
						
							|  |  |  | 	  SETVARATTR (tv, attribute, undo);	/* XXX */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-12-07 14:08:12 +00:00
										 |  |  | 	  stupidly_hack_special_variables (tv->name); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-07-17 14:10:11 +00:00
										 |  |  | 	  free (tvalue); | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  |       else | 
					
						
							|  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2014-02-26 09:36:43 -05:00
										 |  |  | 	  var = find_variable_notempenv (name); | 
					
						
							| 
									
										
										
										
											2016-09-15 16:59:08 -04:00
										 |  |  | 	  if (var == 0) | 
					
						
							|  |  |  | 	    { | 
					
						
							|  |  |  | 	      /* We might have a nameref pointing to something that we can't | 
					
						
							|  |  |  | 		 resolve to a shell variable.  If we do, skip it.  We do a little | 
					
						
							|  |  |  | 		 checking just so we can print an error message. */ | 
					
						
							|  |  |  | 	      refvar = find_variable_nameref_for_create (name, 0); | 
					
						
							|  |  |  | 	      if (refvar == INVALID_NAMEREF_VALUE) | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 	      /* Otherwise we probably have a nameref pointing to a variable | 
					
						
							|  |  |  | 		 that hasn't been created yet. bind_variable will take care | 
					
						
							|  |  |  | 		 of that. */ | 
					
						
							|  |  |  | 	    } | 
					
						
							| 
									
										
										
										
											2002-07-17 14:10:11 +00:00
										 |  |  | 	  if (var == 0) | 
					
						
							|  |  |  | 	    { | 
					
						
							| 
									
										
										
										
											2005-12-07 14:08:12 +00:00
										 |  |  | 	      var = bind_variable (name, (char *)NULL, 0); | 
					
						
							| 
									
										
										
										
											2016-09-15 16:59:08 -04:00
										 |  |  | 	      if (var && no_invisible_vars == 0) | 
					
						
							|  |  |  | 		VSETATTR (var, att_invisible); | 
					
						
							| 
									
										
										
										
											2002-07-17 14:10:11 +00:00
										 |  |  | 	    } | 
					
						
							|  |  |  | 	  else if (var->context != 0) | 
					
						
							|  |  |  | 	    VSETATTR (var, att_propagate); | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |   if (var) | 
					
						
							|  |  |  |     SETVARATTR (var, attribute, undo); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-03-17 21:46:59 +00:00
										 |  |  |   if (var && (exported_p (var) || (attribute & att_exported))) | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  |     array_needs_making++;	/* XXX */ | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  | } |