| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  | This file is set.def, from which is created set.c. | 
					
						
							|  |  |  | It implements the "set" and "unset" builtins in Bash. | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-26 09:36:43 -05:00
										 |  |  | Copyright (C) 1987-2012 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 set.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 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  | #include <stdio.h> | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | #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" | 
					
						
							|  |  |  | #include "../flags.h" | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  | #include "common.h" | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  | #include "bashgetopt.h" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  | #if defined (READLINE) | 
					
						
							|  |  |  | #  include "../input.h" | 
					
						
							|  |  |  | #  include "../bashline.h" | 
					
						
							|  |  |  | #  include <readline/readline.h> | 
					
						
							|  |  |  | #endif | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #if defined (HISTORY) | 
					
						
							|  |  |  | #  include "../bashhist.h" | 
					
						
							|  |  |  | #endif | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-07-17 14:10:11 +00:00
										 |  |  | extern int posixly_correct, ignoreeof, eof_encountered_limit; | 
					
						
							| 
									
										
										
										
											2001-11-13 17:56:06 +00:00
										 |  |  | #if defined (HISTORY) | 
					
						
							|  |  |  | extern int dont_save_function_defs; | 
					
						
							|  |  |  | #endif | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  | #if defined (READLINE) | 
					
						
							| 
									
										
										
										
											2001-04-06 19:14:31 +00:00
										 |  |  | extern int no_line_editing; | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  | #endif /* READLINE */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | $BUILTIN set | 
					
						
							|  |  |  | $FUNCTION set_builtin | 
					
						
							| 
									
										
										
										
											2011-11-22 19:11:26 -05:00
										 |  |  | $SHORT_DOC set [-abefhkmnptuvxBCHP] [-o option-name] [--] [arg ...] | 
					
						
							| 
									
										
										
										
											2009-01-12 13:36:28 +00:00
										 |  |  | Set or unset values of shell options and positional parameters. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Change the value of shell attributes and positional parameters, or | 
					
						
							|  |  |  | display the names and values of shell variables. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Options: | 
					
						
							|  |  |  |   -a  Mark variables which are modified or created for export. | 
					
						
							|  |  |  |   -b  Notify of job termination immediately. | 
					
						
							|  |  |  |   -e  Exit immediately if a command exits with a non-zero status. | 
					
						
							|  |  |  |   -f  Disable file name generation (globbing). | 
					
						
							|  |  |  |   -h  Remember the location of commands as they are looked up. | 
					
						
							|  |  |  |   -k  All assignment arguments are placed in the environment for a | 
					
						
							|  |  |  |       command, not just those that precede the command name. | 
					
						
							|  |  |  |   -m  Job control is enabled. | 
					
						
							|  |  |  |   -n  Read commands but do not execute them. | 
					
						
							|  |  |  |   -o option-name | 
					
						
							|  |  |  |       Set the variable corresponding to option-name: | 
					
						
							|  |  |  |           allexport    same as -a | 
					
						
							|  |  |  |           braceexpand  same as -B | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  | #if defined (READLINE) | 
					
						
							| 
									
										
										
										
											2009-01-12 13:36:28 +00:00
										 |  |  |           emacs        use an emacs-style line editing interface | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  | #endif /* READLINE */ | 
					
						
							| 
									
										
										
										
											2009-01-12 13:36:28 +00:00
										 |  |  |           errexit      same as -e | 
					
						
							|  |  |  |           errtrace     same as -E | 
					
						
							|  |  |  |           functrace    same as -T | 
					
						
							|  |  |  |           hashall      same as -h | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  | #if defined (BANG_HISTORY) | 
					
						
							| 
									
										
										
										
											2009-01-12 13:36:28 +00:00
										 |  |  |           histexpand   same as -H | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  | #endif /* BANG_HISTORY */ | 
					
						
							| 
									
										
										
										
											1997-06-05 14:59:13 +00:00
										 |  |  | #if defined (HISTORY) | 
					
						
							| 
									
										
										
										
											2009-01-12 13:36:28 +00:00
										 |  |  |           history      enable command history | 
					
						
							| 
									
										
										
										
											1997-06-05 14:59:13 +00:00
										 |  |  | #endif | 
					
						
							| 
									
										
										
										
											2009-01-12 13:36:28 +00:00
										 |  |  |           ignoreeof    the shell will not exit upon reading EOF | 
					
						
							|  |  |  |           interactive-comments | 
					
						
							|  |  |  |                        allow comments to appear in interactive commands | 
					
						
							|  |  |  |           keyword      same as -k | 
					
						
							| 
									
										
										
										
											2014-02-26 09:36:43 -05:00
										 |  |  | #if defined (JOB_CONTROL) | 
					
						
							| 
									
										
										
										
											2009-01-12 13:36:28 +00:00
										 |  |  |           monitor      same as -m | 
					
						
							| 
									
										
										
										
											2014-02-26 09:36:43 -05:00
										 |  |  | #endif | 
					
						
							| 
									
										
										
										
											2009-01-12 13:36:28 +00:00
										 |  |  |           noclobber    same as -C | 
					
						
							|  |  |  |           noexec       same as -n | 
					
						
							|  |  |  |           noglob       same as -f | 
					
						
							|  |  |  |           nolog        currently accepted but ignored | 
					
						
							| 
									
										
										
										
											2014-02-26 09:36:43 -05:00
										 |  |  | #if defined (JOB_CONTROL) | 
					
						
							| 
									
										
										
										
											2009-01-12 13:36:28 +00:00
										 |  |  |           notify       same as -b | 
					
						
							| 
									
										
										
										
											2014-02-26 09:36:43 -05:00
										 |  |  | #endif | 
					
						
							| 
									
										
										
										
											2009-01-12 13:36:28 +00:00
										 |  |  |           nounset      same as -u | 
					
						
							|  |  |  |           onecmd       same as -t | 
					
						
							|  |  |  |           physical     same as -P | 
					
						
							|  |  |  |           pipefail     the return value of a pipeline is the status of | 
					
						
							|  |  |  |                        the last command to exit with a non-zero status, | 
					
						
							|  |  |  |                        or zero if no command exited with a non-zero status | 
					
						
							|  |  |  |           posix        change the behavior of bash where the default | 
					
						
							|  |  |  |                        operation differs from the Posix standard to | 
					
						
							|  |  |  |                        match the standard | 
					
						
							|  |  |  |           privileged   same as -p | 
					
						
							|  |  |  |           verbose      same as -v | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  | #if defined (READLINE) | 
					
						
							| 
									
										
										
										
											2009-01-12 13:36:28 +00:00
										 |  |  |           vi           use a vi-style line editing interface | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  | #endif /* READLINE */ | 
					
						
							| 
									
										
										
										
											2009-01-12 13:36:28 +00:00
										 |  |  |           xtrace       same as -x | 
					
						
							|  |  |  |   -p  Turned on whenever the real and effective user ids do not match. | 
					
						
							|  |  |  |       Disables processing of the $ENV file and importing of shell | 
					
						
							|  |  |  |       functions.  Turning this option off causes the effective uid and | 
					
						
							|  |  |  |       gid to be set to the real uid and gid. | 
					
						
							|  |  |  |   -t  Exit after reading and executing one command. | 
					
						
							|  |  |  |   -u  Treat unset variables as an error when substituting. | 
					
						
							|  |  |  |   -v  Print shell input lines as they are read. | 
					
						
							|  |  |  |   -x  Print commands and their arguments as they are executed. | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  | #if defined (BRACE_EXPANSION) | 
					
						
							| 
									
										
										
										
											2009-01-12 13:36:28 +00:00
										 |  |  |   -B  the shell will perform brace expansion | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  | #endif /* BRACE_EXPANSION */ | 
					
						
							| 
									
										
										
										
											2009-01-12 13:36:28 +00:00
										 |  |  |   -C  If set, disallow existing regular files to be overwritten | 
					
						
							|  |  |  |       by redirection of output. | 
					
						
							|  |  |  |   -E  If set, the ERR trap is inherited by shell functions. | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  | #if defined (BANG_HISTORY) | 
					
						
							| 
									
										
										
										
											2009-01-12 13:36:28 +00:00
										 |  |  |   -H  Enable ! style history substitution.  This flag is on | 
					
						
							|  |  |  |       by default when the shell is interactive. | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  | #endif /* BANG_HISTORY */ | 
					
						
							| 
									
										
										
										
											2014-02-26 09:36:43 -05:00
										 |  |  |   -P  If set, do not resolve symbolic links when executing commands | 
					
						
							| 
									
										
										
										
											2009-01-12 13:36:28 +00:00
										 |  |  |       such as cd which change the current directory. | 
					
						
							|  |  |  |   -T  If set, the DEBUG trap is inherited by shell functions. | 
					
						
							| 
									
										
										
										
											2011-11-22 19:11:26 -05:00
										 |  |  |   --  Assign any remaining arguments to the positional parameters. | 
					
						
							|  |  |  |       If there are no remaining arguments, the positional parameters | 
					
						
							|  |  |  |       are unset. | 
					
						
							| 
									
										
										
										
											2009-01-12 13:36:28 +00:00
										 |  |  |   -   Assign any remaining arguments to the positional parameters. | 
					
						
							|  |  |  |       The -x and -v options are turned off. | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | Using + rather than - causes these flags to be turned off.  The | 
					
						
							|  |  |  | flags can also be used upon invocation of the shell.  The current | 
					
						
							|  |  |  | set of flags may be found in $-.  The remaining n ARGs are positional | 
					
						
							|  |  |  | parameters and are assigned, in order, to $1, $2, .. $n.  If no | 
					
						
							|  |  |  | ARGs are given, all shell variables are printed. | 
					
						
							| 
									
										
										
										
											2009-01-12 13:36:28 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | Exit Status: | 
					
						
							|  |  |  | Returns success unless an invalid option is given. | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  | $END | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-07-17 14:10:11 +00:00
										 |  |  | typedef int setopt_set_func_t __P((int, char *)); | 
					
						
							|  |  |  | typedef int setopt_get_func_t __P((char *)); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-11-13 17:56:06 +00:00
										 |  |  | static void print_minus_o_option __P((char *, int, int)); | 
					
						
							|  |  |  | static void print_all_shell_variables __P((void)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int set_ignoreeof __P((int, char *)); | 
					
						
							|  |  |  | static int set_posix_mode __P((int, char *)); | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | #if defined (READLINE) | 
					
						
							| 
									
										
										
										
											2001-11-13 17:56:06 +00:00
										 |  |  | static int set_edit_mode __P((int, char *)); | 
					
						
							|  |  |  | static int get_edit_mode __P((char *)); | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  | #endif | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #if defined (HISTORY) | 
					
						
							| 
									
										
										
										
											2001-11-13 17:56:06 +00:00
										 |  |  | static int bash_set_history __P((int, char *)); | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  | #endif | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-01-12 13:36:28 +00:00
										 |  |  | static const char * const on = "on"; | 
					
						
							|  |  |  | static const char * const off = "off"; | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-07-17 14:10:11 +00:00
										 |  |  | /* A struct used to match long options for set -o to the corresponding | 
					
						
							|  |  |  |    option letter or internal variable.  The functions can be called to | 
					
						
							|  |  |  |    dynamically generate values. */ | 
					
						
							| 
									
										
										
										
											2009-01-12 13:36:28 +00:00
										 |  |  | const struct { | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  |   char *name; | 
					
						
							|  |  |  |   int letter; | 
					
						
							| 
									
										
										
										
											2002-07-17 14:10:11 +00:00
										 |  |  |   int *variable; | 
					
						
							|  |  |  |   setopt_set_func_t *set_func; | 
					
						
							|  |  |  |   setopt_get_func_t *get_func; | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  | } o_options[] = { | 
					
						
							| 
									
										
										
										
											2002-07-17 14:10:11 +00:00
										 |  |  |   { "allexport",  'a', (int *)NULL, (setopt_set_func_t *)NULL, (setopt_get_func_t *)NULL }, | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  | #if defined (BRACE_EXPANSION) | 
					
						
							| 
									
										
										
										
											2002-07-17 14:10:11 +00:00
										 |  |  |   { "braceexpand",'B', (int *)NULL, (setopt_set_func_t *)NULL, (setopt_get_func_t *)NULL  }, | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  | #endif | 
					
						
							| 
									
										
										
										
											2002-07-17 14:10:11 +00:00
										 |  |  | #if defined (READLINE) | 
					
						
							|  |  |  |   { "emacs",     '\0', (int *)NULL, set_edit_mode, get_edit_mode }, | 
					
						
							|  |  |  | #endif | 
					
						
							|  |  |  |   { "errexit",	  'e', (int *)NULL, (setopt_set_func_t *)NULL, (setopt_get_func_t *)NULL  }, | 
					
						
							| 
									
										
										
										
											2004-07-27 13:29:18 +00:00
										 |  |  |   { "errtrace",	  'E', (int *)NULL, (setopt_set_func_t *)NULL, (setopt_get_func_t *)NULL  }, | 
					
						
							|  |  |  |   { "functrace",  'T', (int *)NULL, (setopt_set_func_t *)NULL, (setopt_get_func_t *)NULL  }, | 
					
						
							| 
									
										
										
										
											2002-07-17 14:10:11 +00:00
										 |  |  |   { "hashall",    'h', (int *)NULL, (setopt_set_func_t *)NULL, (setopt_get_func_t *)NULL  }, | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  | #if defined (BANG_HISTORY) | 
					
						
							| 
									
										
										
										
											2002-07-17 14:10:11 +00:00
										 |  |  |   { "histexpand", 'H', (int *)NULL, (setopt_set_func_t *)NULL, (setopt_get_func_t *)NULL  }, | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  | #endif /* BANG_HISTORY */ | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  | #if defined (HISTORY) | 
					
						
							| 
									
										
										
										
											2008-11-18 13:15:12 +00:00
										 |  |  |   { "history",   '\0', &enable_history_list, bash_set_history, (setopt_get_func_t *)NULL }, | 
					
						
							| 
									
										
										
										
											2001-11-13 17:56:06 +00:00
										 |  |  | #endif | 
					
						
							| 
									
										
										
										
											2002-07-17 14:10:11 +00:00
										 |  |  |   { "ignoreeof", '\0', &ignoreeof, set_ignoreeof, (setopt_get_func_t *)NULL }, | 
					
						
							|  |  |  |   { "interactive-comments", '\0', &interactive_comments, (setopt_set_func_t *)NULL, (setopt_get_func_t *)NULL }, | 
					
						
							|  |  |  |   { "keyword",    'k', (int *)NULL, (setopt_set_func_t *)NULL, (setopt_get_func_t *)NULL  }, | 
					
						
							| 
									
										
										
										
											2014-02-26 09:36:43 -05:00
										 |  |  | #if defined (JOB_CONTROL) | 
					
						
							| 
									
										
										
										
											2002-07-17 14:10:11 +00:00
										 |  |  |   { "monitor",	  'm', (int *)NULL, (setopt_set_func_t *)NULL, (setopt_get_func_t *)NULL  }, | 
					
						
							| 
									
										
										
										
											2014-02-26 09:36:43 -05:00
										 |  |  | #endif | 
					
						
							| 
									
										
										
										
											2002-07-17 14:10:11 +00:00
										 |  |  |   { "noclobber",  'C', (int *)NULL, (setopt_set_func_t *)NULL, (setopt_get_func_t *)NULL  }, | 
					
						
							|  |  |  |   { "noexec",	  'n', (int *)NULL, (setopt_set_func_t *)NULL, (setopt_get_func_t *)NULL  }, | 
					
						
							|  |  |  |   { "noglob",	  'f', (int *)NULL, (setopt_set_func_t *)NULL, (setopt_get_func_t *)NULL  }, | 
					
						
							| 
									
										
										
										
											2001-11-13 17:56:06 +00:00
										 |  |  | #if defined (HISTORY) | 
					
						
							| 
									
										
										
										
											2002-07-17 14:10:11 +00:00
										 |  |  |   { "nolog",     '\0', &dont_save_function_defs, (setopt_set_func_t *)NULL, (setopt_get_func_t *)NULL }, | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  | #endif | 
					
						
							| 
									
										
										
										
											2002-07-17 14:10:11 +00:00
										 |  |  | #if defined (JOB_CONTROL) | 
					
						
							|  |  |  |   { "notify",	  'b', (int *)NULL, (setopt_set_func_t *)NULL, (setopt_get_func_t *)NULL  }, | 
					
						
							|  |  |  | #endif /* JOB_CONTROL */ | 
					
						
							|  |  |  |   { "nounset",	  'u', (int *)NULL, (setopt_set_func_t *)NULL, (setopt_get_func_t *)NULL  }, | 
					
						
							|  |  |  |   { "onecmd",	  't', (int *)NULL, (setopt_set_func_t *)NULL, (setopt_get_func_t *)NULL }, | 
					
						
							|  |  |  |   { "physical",   'P', (int *)NULL, (setopt_set_func_t *)NULL, (setopt_get_func_t *)NULL  }, | 
					
						
							| 
									
										
										
										
											2004-07-27 13:29:18 +00:00
										 |  |  |   { "pipefail",  '\0', &pipefail_opt, (setopt_set_func_t *)NULL, (setopt_get_func_t *)NULL  }, | 
					
						
							| 
									
										
										
										
											2002-07-17 14:10:11 +00:00
										 |  |  |   { "posix",     '\0', &posixly_correct, set_posix_mode, (setopt_get_func_t *)NULL }, | 
					
						
							|  |  |  |   { "privileged", 'p', (int *)NULL, (setopt_set_func_t *)NULL, (setopt_get_func_t *)NULL  }, | 
					
						
							|  |  |  |   { "verbose",	  'v', (int *)NULL, (setopt_set_func_t *)NULL, (setopt_get_func_t *)NULL  }, | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  | #if defined (READLINE) | 
					
						
							| 
									
										
										
										
											2002-07-17 14:10:11 +00:00
										 |  |  |   { "vi",        '\0', (int *)NULL, set_edit_mode, get_edit_mode }, | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  | #endif | 
					
						
							| 
									
										
										
										
											2002-07-17 14:10:11 +00:00
										 |  |  |   { "xtrace",	  'x', (int *)NULL, (setopt_set_func_t *)NULL, (setopt_get_func_t *)NULL  }, | 
					
						
							|  |  |  |   {(char *)NULL, 0 , (int *)NULL, (setopt_set_func_t *)NULL, (setopt_get_func_t *)NULL }, | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-07-17 14:10:11 +00:00
										 |  |  | #define N_O_OPTIONS	(sizeof (o_options) / sizeof (o_options[0])) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  | #define GET_BINARY_O_OPTION_VALUE(i, name) \ | 
					
						
							| 
									
										
										
										
											2002-07-17 14:10:11 +00:00
										 |  |  |   ((o_options[i].get_func) ? (*o_options[i].get_func) (name) \ | 
					
						
							|  |  |  | 			   : (*o_options[i].variable)) | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | #define SET_BINARY_O_OPTION_VALUE(i, onoff, name) \ | 
					
						
							| 
									
										
										
										
											2002-07-17 14:10:11 +00:00
										 |  |  |   ((o_options[i].set_func) ? (*o_options[i].set_func) (onoff, name) \ | 
					
						
							|  |  |  | 			   : (*o_options[i].variable = (onoff == FLAG_ON))) | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | int | 
					
						
							|  |  |  | minus_o_option_value (name) | 
					
						
							|  |  |  |      char *name; | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   register int	i; | 
					
						
							|  |  |  |   int *on_or_off; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   for (i = 0; o_options[i].name; i++) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |       if (STREQ (name, o_options[i].name)) | 
					
						
							|  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2002-07-17 14:10:11 +00:00
										 |  |  | 	  if (o_options[i].letter) | 
					
						
							|  |  |  | 	    { | 
					
						
							|  |  |  | 	      on_or_off = find_flag (o_options[i].letter); | 
					
						
							|  |  |  | 	      return ((on_or_off == FLAG_UNKNOWN) ? -1 : *on_or_off); | 
					
						
							|  |  |  | 	    } | 
					
						
							|  |  |  | 	  else | 
					
						
							|  |  |  | 	    return (GET_BINARY_O_OPTION_VALUE (i, name)); | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2001-04-06 19:14:31 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  |   return (-1); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  | #define MINUS_O_FORMAT "%-15s\t%s\n" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1998-04-17 19:52:44 +00:00
										 |  |  | static void | 
					
						
							|  |  |  | print_minus_o_option (name, value, pflag) | 
					
						
							|  |  |  |      char *name; | 
					
						
							|  |  |  |      int value, pflag; | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											1998-04-17 19:52:44 +00:00
										 |  |  |   if (pflag == 0) | 
					
						
							|  |  |  |     printf (MINUS_O_FORMAT, name, value ? on : off); | 
					
						
							|  |  |  |   else | 
					
						
							|  |  |  |     printf ("set %co %s\n", value ? '-' : '+', name); | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											1998-04-17 19:52:44 +00:00
										 |  |  | void | 
					
						
							|  |  |  | list_minus_o_opts (mode, reusable) | 
					
						
							|  |  |  |      int mode, reusable; | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  | { | 
					
						
							|  |  |  |   register int	i; | 
					
						
							|  |  |  |   int *on_or_off, value; | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-07-17 14:10:11 +00:00
										 |  |  |   for (i = 0; o_options[i].name; i++) | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2002-07-17 14:10:11 +00:00
										 |  |  |       if (o_options[i].letter) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 	  value = 0; | 
					
						
							|  |  |  | 	  on_or_off = find_flag (o_options[i].letter); | 
					
						
							|  |  |  | 	  if (on_or_off == FLAG_UNKNOWN) | 
					
						
							|  |  |  | 	    on_or_off = &value; | 
					
						
							|  |  |  | 	  if (mode == -1 || mode == *on_or_off) | 
					
						
							|  |  |  | 	    print_minus_o_option (o_options[i].name, *on_or_off, reusable); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  |       else | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 	  value = GET_BINARY_O_OPTION_VALUE (i, o_options[i].name); | 
					
						
							|  |  |  | 	  if (mode == -1 || mode == value) | 
					
						
							|  |  |  | 	    print_minus_o_option (o_options[i].name, value, reusable); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-03-17 21:46:59 +00:00
										 |  |  | char ** | 
					
						
							|  |  |  | get_minus_o_opts () | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   char **ret; | 
					
						
							| 
									
										
										
										
											2002-07-17 14:10:11 +00:00
										 |  |  |   int i; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   ret = strvec_create (N_O_OPTIONS + 1); | 
					
						
							|  |  |  |   for (i = 0; o_options[i].name; i++) | 
					
						
							|  |  |  |     ret[i] = o_options[i].name; | 
					
						
							|  |  |  |   ret[i] = (char *)NULL; | 
					
						
							| 
									
										
										
										
											2000-03-17 21:46:59 +00:00
										 |  |  |   return ret; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  | static int | 
					
						
							|  |  |  | set_ignoreeof (on_or_off, option_name) | 
					
						
							|  |  |  |      int on_or_off; | 
					
						
							|  |  |  |      char *option_name; | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   ignoreeof = on_or_off == FLAG_ON; | 
					
						
							|  |  |  |   unbind_variable ("ignoreeof"); | 
					
						
							|  |  |  |   if (ignoreeof) | 
					
						
							| 
									
										
										
										
											2005-12-07 14:08:12 +00:00
										 |  |  |     bind_variable ("IGNOREEOF", "10", 0);  | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  |   else | 
					
						
							|  |  |  |     unbind_variable ("IGNOREEOF"); | 
					
						
							|  |  |  |   sv_ignoreeof ("IGNOREEOF"); | 
					
						
							|  |  |  |   return 0; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											1997-06-05 14:59:13 +00:00
										 |  |  | static int | 
					
						
							|  |  |  | set_posix_mode (on_or_off, option_name) | 
					
						
							|  |  |  |      int on_or_off; | 
					
						
							|  |  |  |      char *option_name; | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   posixly_correct = on_or_off == FLAG_ON; | 
					
						
							|  |  |  |   if (posixly_correct == 0) | 
					
						
							|  |  |  |     unbind_variable ("POSIXLY_CORRECT"); | 
					
						
							|  |  |  |   else | 
					
						
							| 
									
										
										
										
											2005-12-07 14:08:12 +00:00
										 |  |  |     bind_variable ("POSIXLY_CORRECT", "y", 0); | 
					
						
							| 
									
										
										
										
											1997-06-05 14:59:13 +00:00
										 |  |  |   sv_strict_posix ("POSIXLY_CORRECT"); | 
					
						
							|  |  |  |   return (0); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  | #if defined (READLINE) | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  | /* Magic.  This code `knows' how readline handles rl_editing_mode. */ | 
					
						
							|  |  |  | static int | 
					
						
							|  |  |  | set_edit_mode (on_or_off, option_name) | 
					
						
							|  |  |  |      int on_or_off; | 
					
						
							|  |  |  |      char *option_name; | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   int isemacs; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   if (on_or_off == FLAG_ON) | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  |       rl_variable_bind ("editing-mode", option_name); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       if (interactive) | 
					
						
							|  |  |  | 	with_input_from_stdin (); | 
					
						
							|  |  |  |       no_line_editing = 0; | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  |     } | 
					
						
							|  |  |  |   else | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  |       isemacs = rl_editing_mode == 1; | 
					
						
							|  |  |  |       if ((isemacs && *option_name == 'e') || (!isemacs && *option_name == 'v')) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 	  if (interactive) | 
					
						
							|  |  |  | 	    with_input_from_stream (stdin, "stdin"); | 
					
						
							|  |  |  | 	  no_line_editing = 1; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  |   return 1-no_line_editing; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int | 
					
						
							|  |  |  | get_edit_mode (name) | 
					
						
							|  |  |  |      char *name; | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   return (*name == 'e' ? no_line_editing == 0 && rl_editing_mode == 1 | 
					
						
							|  |  |  | 		       : no_line_editing == 0 && rl_editing_mode == 0); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  | #endif /* READLINE */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  | #if defined (HISTORY) | 
					
						
							|  |  |  | static int | 
					
						
							|  |  |  | bash_set_history (on_or_off, option_name) | 
					
						
							|  |  |  |      int on_or_off; | 
					
						
							|  |  |  |      char *option_name; | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   if (on_or_off == FLAG_ON) | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2008-11-18 13:15:12 +00:00
										 |  |  |       enable_history_list = 1; | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  |       bash_history_enable (); | 
					
						
							|  |  |  |       if (history_lines_this_session == 0) | 
					
						
							|  |  |  | 	load_history (); | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  |   else | 
					
						
							| 
									
										
										
										
											2008-11-18 13:15:12 +00:00
										 |  |  |     { | 
					
						
							|  |  |  |       enable_history_list = 0; | 
					
						
							|  |  |  |       bash_history_disable (); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   return (1 - enable_history_list); | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  | #endif | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  | int | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  | set_minus_o_option (on_or_off, option_name) | 
					
						
							|  |  |  |      int on_or_off; | 
					
						
							|  |  |  |      char *option_name; | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  |   register int i; | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-07-17 14:10:11 +00:00
										 |  |  |   for (i = 0; o_options[i].name; i++) | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  |       if (STREQ (option_name, o_options[i].name)) | 
					
						
							| 
									
										
										
										
											2001-04-06 19:14:31 +00:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2002-07-17 14:10:11 +00:00
										 |  |  | 	  if (o_options[i].letter == 0) | 
					
						
							|  |  |  | 	    { | 
					
						
							|  |  |  | 	      SET_BINARY_O_OPTION_VALUE (i, on_or_off, option_name); | 
					
						
							|  |  |  | 	      return (EXECUTION_SUCCESS); | 
					
						
							|  |  |  | 	    } | 
					
						
							|  |  |  | 	  else | 
					
						
							|  |  |  | 	    { | 
					
						
							|  |  |  | 	      if (change_flag (o_options[i].letter, on_or_off) == FLAG_ERROR) | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 		  sh_invalidoptname (option_name); | 
					
						
							|  |  |  | 		  return (EXECUTION_FAILURE); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	      else | 
					
						
							|  |  |  | 		return (EXECUTION_SUCCESS); | 
					
						
							|  |  |  | 	    } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-04-06 19:14:31 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2002-07-17 14:10:11 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |   sh_invalidoptname (option_name); | 
					
						
							| 
									
										
										
										
											2009-01-12 13:36:28 +00:00
										 |  |  |   return (EX_USAGE); | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  | static void | 
					
						
							|  |  |  | print_all_shell_variables () | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   SHELL_VAR **vars; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   vars = all_shell_variables (); | 
					
						
							|  |  |  |   if (vars) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |       print_var_list (vars); | 
					
						
							|  |  |  |       free (vars); | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-04-06 19:14:31 +00:00
										 |  |  |   /* POSIX.2 does not allow function names and definitions to be output when | 
					
						
							|  |  |  |      `set' is invoked without options (PASC Interp #202). */ | 
					
						
							|  |  |  |   if (posixly_correct == 0) | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2001-04-06 19:14:31 +00:00
										 |  |  |       vars = all_shell_functions (); | 
					
						
							|  |  |  |       if (vars) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 	  print_func_list (vars); | 
					
						
							|  |  |  | 	  free (vars); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void | 
					
						
							|  |  |  | set_shellopts () | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   char *value; | 
					
						
							| 
									
										
										
										
											2002-07-17 14:10:11 +00:00
										 |  |  |   char tflag[N_O_OPTIONS]; | 
					
						
							| 
									
										
										
										
											1998-04-17 19:52:44 +00:00
										 |  |  |   int vsize, i, vptr, *ip, exported; | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  |   SHELL_VAR *v; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   for (vsize = i = 0; o_options[i].name; i++) | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2002-07-17 14:10:11 +00:00
										 |  |  |       tflag[i] = 0; | 
					
						
							|  |  |  |       if (o_options[i].letter) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 	  ip = find_flag (o_options[i].letter); | 
					
						
							|  |  |  | 	  if (ip && *ip) | 
					
						
							|  |  |  | 	    { | 
					
						
							|  |  |  | 	      vsize += strlen (o_options[i].name) + 1; | 
					
						
							|  |  |  | 	      tflag[i] = 1; | 
					
						
							|  |  |  | 	    } | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  |       else if (GET_BINARY_O_OPTION_VALUE (i, o_options[i].name)) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 	  vsize += strlen (o_options[i].name) + 1; | 
					
						
							|  |  |  | 	  tflag[i] = 1; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-11-13 17:56:06 +00:00
										 |  |  |   value = (char *)xmalloc (vsize + 1); | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |   for (i = vptr = 0; o_options[i].name; i++) | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2002-07-17 14:10:11 +00:00
										 |  |  |       if (tflag[i]) | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  | 	  strcpy (value + vptr, o_options[i].name); | 
					
						
							|  |  |  | 	  vptr += strlen (o_options[i].name); | 
					
						
							|  |  |  | 	  value[vptr++] = ':'; | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2002-07-17 14:10:11 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											1997-06-05 14:59:13 +00:00
										 |  |  |   if (vptr) | 
					
						
							|  |  |  |     vptr--;			/* cut off trailing colon */ | 
					
						
							|  |  |  |   value[vptr] = '\0'; | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |   v = find_variable ("SHELLOPTS"); | 
					
						
							| 
									
										
										
										
											1998-04-17 19:52:44 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |   /* Turn off the read-only attribute so we can bind the new value, and | 
					
						
							|  |  |  |      note whether or not the variable was exported. */ | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  |   if (v) | 
					
						
							| 
									
										
										
										
											1998-04-17 19:52:44 +00:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2000-03-17 21:46:59 +00:00
										 |  |  |       VUNSETATTR (v, att_readonly); | 
					
						
							| 
									
										
										
										
											1998-04-17 19:52:44 +00:00
										 |  |  |       exported = exported_p (v); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   else | 
					
						
							|  |  |  |     exported = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-12-07 14:08:12 +00:00
										 |  |  |   v = bind_variable ("SHELLOPTS", value, 0); | 
					
						
							| 
									
										
										
										
											1998-04-17 19:52:44 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |   /* Turn the read-only attribute back on, and turn off the export attribute | 
					
						
							|  |  |  |      if it was set implicitly by mark_modified_vars and SHELLOPTS was not | 
					
						
							|  |  |  |      exported before we bound the new value. */ | 
					
						
							| 
									
										
										
										
											2000-03-17 21:46:59 +00:00
										 |  |  |   VSETATTR (v, att_readonly); | 
					
						
							| 
									
										
										
										
											1998-04-17 19:52:44 +00:00
										 |  |  |   if (mark_modified_vars && exported == 0 && exported_p (v)) | 
					
						
							| 
									
										
										
										
											2000-03-17 21:46:59 +00:00
										 |  |  |     VUNSETATTR (v, att_exported); | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |   free (value); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void | 
					
						
							|  |  |  | parse_shellopts (value) | 
					
						
							|  |  |  |      char *value; | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   char *vname; | 
					
						
							|  |  |  |   int vptr; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   vptr = 0; | 
					
						
							|  |  |  |   while (vname = extract_colon_unit (value, &vptr)) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |       set_minus_o_option (FLAG_ON, vname); | 
					
						
							|  |  |  |       free (vname); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void | 
					
						
							| 
									
										
										
										
											1998-04-17 19:52:44 +00:00
										 |  |  | initialize_shell_options (no_shellopts) | 
					
						
							|  |  |  |      int no_shellopts; | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  | { | 
					
						
							|  |  |  |   char *temp; | 
					
						
							| 
									
										
										
										
											1997-06-05 14:59:13 +00:00
										 |  |  |   SHELL_VAR *var; | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											1998-04-17 19:52:44 +00:00
										 |  |  |   if (no_shellopts == 0) | 
					
						
							| 
									
										
										
										
											1997-06-05 14:59:13 +00:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											1998-04-17 19:52:44 +00:00
										 |  |  |       var = find_variable ("SHELLOPTS"); | 
					
						
							|  |  |  |       /* set up any shell options we may have inherited. */ | 
					
						
							|  |  |  |       if (var && imported_p (var)) | 
					
						
							| 
									
										
										
										
											1997-06-05 14:59:13 +00:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2009-01-12 13:36:28 +00:00
										 |  |  | 	  temp = (array_p (var) || assoc_p (var)) ? (char *)NULL : savestring (value_cell (var)); | 
					
						
							| 
									
										
										
										
											1998-04-17 19:52:44 +00:00
										 |  |  | 	  if (temp) | 
					
						
							|  |  |  | 	    { | 
					
						
							|  |  |  | 	      parse_shellopts (temp); | 
					
						
							|  |  |  | 	      free (temp); | 
					
						
							|  |  |  | 	    } | 
					
						
							| 
									
										
										
										
											1997-06-05 14:59:13 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |   /* Set up the $SHELLOPTS variable. */ | 
					
						
							|  |  |  |   set_shellopts (); | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-04-06 19:14:31 +00:00
										 |  |  | /* Reset the values of the -o options that are not also shell flags.  This is | 
					
						
							|  |  |  |    called from execute_cmd.c:initialize_subshell() when setting up a subshell | 
					
						
							|  |  |  |    to run an executable shell script without a leading `#!'. */ | 
					
						
							| 
									
										
										
										
											1997-06-05 14:59:13 +00:00
										 |  |  | void | 
					
						
							|  |  |  | reset_shell_options () | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | #if defined (HISTORY) | 
					
						
							| 
									
										
										
										
											2008-11-18 13:15:12 +00:00
										 |  |  |   remember_on_history = enable_history_list = 1; | 
					
						
							| 
									
										
										
										
											1997-06-05 14:59:13 +00:00
										 |  |  | #endif | 
					
						
							| 
									
										
										
										
											2001-04-06 19:14:31 +00:00
										 |  |  |   ignoreeof = 0; | 
					
						
							| 
									
										
										
										
											1997-06-05 14:59:13 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  | /* Set some flags from the word values in the input list.  If LIST is empty, | 
					
						
							|  |  |  |    then print out the values of the variables instead.  If LIST contains | 
					
						
							|  |  |  |    non-flags, then set $1 - $9 to the successive words of LIST. */ | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  | int | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  | set_builtin (list) | 
					
						
							|  |  |  |      WORD_LIST *list; | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2009-01-12 13:36:28 +00:00
										 |  |  |   int on_or_off, flag_name, force_assignment, opts_changed, rv, r; | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  |   register char *arg; | 
					
						
							| 
									
										
										
										
											2002-07-17 14:10:11 +00:00
										 |  |  |   char s[3]; | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  |   if (list == 0) | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  |       print_all_shell_variables (); | 
					
						
							| 
									
										
										
										
											2009-01-12 13:36:28 +00:00
										 |  |  |       return (sh_chkwrite (EXECUTION_SUCCESS)); | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /* Check validity of flag arguments. */ | 
					
						
							| 
									
										
										
										
											2009-01-12 13:36:28 +00:00
										 |  |  |   rv = EXECUTION_SUCCESS; | 
					
						
							| 
									
										
										
										
											2002-07-17 14:10:11 +00:00
										 |  |  |   reset_internal_getopt (); | 
					
						
							|  |  |  |   while ((flag_name = internal_getopt (list, optflags)) != -1) | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2002-07-17 14:10:11 +00:00
										 |  |  |       switch (flag_name) | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2002-07-17 14:10:11 +00:00
										 |  |  | 	  case '?': | 
					
						
							|  |  |  | 	    builtin_usage (); | 
					
						
							|  |  |  | 	    return (list_optopt == '?' ? EXECUTION_SUCCESS : EX_USAGE); | 
					
						
							|  |  |  | 	  default: | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  | 	    break; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2002-07-17 14:10:11 +00:00
										 |  |  |      | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  |   /* Do the set command.  While the list consists of words starting with | 
					
						
							|  |  |  |      '-' or '+' treat them as flags, otherwise, start assigning them to | 
					
						
							|  |  |  |      $1 ... $n. */ | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  |   for (force_assignment = opts_changed = 0; list; ) | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  |       arg = list->word->word; | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |       /* If the argument is `--' or `-' then signal the end of the list | 
					
						
							|  |  |  | 	 and remember the remaining arguments. */ | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  |       if (arg[0] == '-' && (!arg[1] || (arg[1] == '-' && !arg[2]))) | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  | 	{ | 
					
						
							|  |  |  | 	  list = list->next; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	  /* `set --' unsets the positional parameters. */ | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  | 	  if (arg[1] == '-') | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  | 	    force_assignment = 1; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	  /* Until told differently, the old shell behaviour of | 
					
						
							|  |  |  | 	     `set - [arg ...]' being equivalent to `set +xv [arg ...]' | 
					
						
							|  |  |  | 	     stands.  Posix.2 says the behaviour is marked as obsolescent. */ | 
					
						
							|  |  |  | 	  else | 
					
						
							|  |  |  | 	    { | 
					
						
							|  |  |  | 	      change_flag ('x', '+'); | 
					
						
							|  |  |  | 	      change_flag ('v', '+'); | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  | 	      opts_changed = 1; | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  | 	    } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	  break; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  |       if ((on_or_off = *arg) && (on_or_off == '-' || on_or_off == '+')) | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  | 	  while (flag_name = *++arg) | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  | 	    { | 
					
						
							|  |  |  | 	      if (flag_name == '?') | 
					
						
							|  |  |  | 		{ | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  | 		  builtin_usage (); | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  | 		  return (EXECUTION_SUCCESS); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	      else if (flag_name == 'o') /* -+o option-name */ | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 		  char *option_name; | 
					
						
							|  |  |  | 		  WORD_LIST *opt; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		  opt = list->next; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  | 		  if (opt == 0) | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  | 		    { | 
					
						
							| 
									
										
										
										
											1998-04-17 19:52:44 +00:00
										 |  |  | 		      list_minus_o_opts (-1, (on_or_off == '+')); | 
					
						
							| 
									
										
										
										
											2009-01-12 13:36:28 +00:00
										 |  |  | 		      rv = sh_chkwrite (rv); | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  | 		      continue; | 
					
						
							|  |  |  | 		    } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		  option_name = opt->word->word; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  | 		  if (option_name == 0 || *option_name == '\0' || | 
					
						
							|  |  |  | 		      *option_name == '-' || *option_name == '+') | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  | 		    { | 
					
						
							| 
									
										
										
										
											1998-04-17 19:52:44 +00:00
										 |  |  | 		      list_minus_o_opts (-1, (on_or_off == '+')); | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  | 		      continue; | 
					
						
							|  |  |  | 		    } | 
					
						
							|  |  |  | 		  list = list->next; /* Skip over option name. */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  | 		  opts_changed = 1; | 
					
						
							| 
									
										
										
										
											2009-01-12 13:36:28 +00:00
										 |  |  | 		  if ((r = set_minus_o_option (on_or_off, option_name)) != EXECUTION_SUCCESS) | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  | 		    { | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  | 		      set_shellopts (); | 
					
						
							| 
									
										
										
										
											2009-01-12 13:36:28 +00:00
										 |  |  | 		      return (r); | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  | 		    } | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  | 	      else if (change_flag (flag_name, on_or_off) == FLAG_ERROR) | 
					
						
							|  |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2002-07-17 14:10:11 +00:00
										 |  |  | 		  s[0] = on_or_off; | 
					
						
							|  |  |  | 		  s[1] = flag_name; | 
					
						
							|  |  |  | 		  s[2] = '\0'; | 
					
						
							|  |  |  | 		  sh_invalidopt (s); | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  | 		  builtin_usage (); | 
					
						
							|  |  |  | 		  set_shellopts (); | 
					
						
							|  |  |  | 		  return (EXECUTION_FAILURE); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	      opts_changed = 1; | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  | 	    } | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  |       else | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 	  break; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  |       list = list->next; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /* Assigning $1 ... $n */ | 
					
						
							|  |  |  |   if (list || force_assignment) | 
					
						
							|  |  |  |     remember_args (list, 1); | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  |   /* Set up new value of $SHELLOPTS */ | 
					
						
							|  |  |  |   if (opts_changed) | 
					
						
							|  |  |  |     set_shellopts (); | 
					
						
							| 
									
										
										
										
											2009-01-12 13:36:28 +00:00
										 |  |  |   return (rv); | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | $BUILTIN unset | 
					
						
							|  |  |  | $FUNCTION unset_builtin | 
					
						
							| 
									
										
										
										
											2014-02-26 09:36:43 -05:00
										 |  |  | $SHORT_DOC unset [-f] [-v] [-n] [name ...] | 
					
						
							| 
									
										
										
										
											2009-01-12 13:36:28 +00:00
										 |  |  | Unset values and attributes of shell variables and functions. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | For each NAME, remove the corresponding variable or function. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Options: | 
					
						
							|  |  |  |   -f	treat each NAME as a shell function | 
					
						
							|  |  |  |   -v	treat each NAME as a shell variable | 
					
						
							| 
									
										
										
										
											2014-02-26 09:36:43 -05:00
										 |  |  |   -n	treat each NAME as a name reference and unset the variable itself | 
					
						
							|  |  |  | 	rather than the variable it references | 
					
						
							| 
									
										
										
										
											2009-01-12 13:36:28 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | Without options, unset first tries to unset a variable, and if that fails, | 
					
						
							|  |  |  | tries to unset a function. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Some variables cannot be unset; also see `readonly'. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Exit Status: | 
					
						
							|  |  |  | Returns success unless an invalid option is given or a NAME is read-only. | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  | $END | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  | #define NEXT_VARIABLE()	any_failed++; list = list->next; continue; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | int | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  | unset_builtin (list) | 
					
						
							|  |  |  |   WORD_LIST *list; | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2014-02-26 09:36:43 -05:00
										 |  |  |   int unset_function, unset_variable, unset_array, opt, nameref, any_failed; | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  |   char *name; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-26 09:36:43 -05:00
										 |  |  |   unset_function = unset_variable = unset_array = nameref = any_failed = 0; | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  |   reset_internal_getopt (); | 
					
						
							| 
									
										
										
										
											2014-02-26 09:36:43 -05:00
										 |  |  |   while ((opt = internal_getopt (list, "fnv")) != -1) | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  |     { | 
					
						
							|  |  |  |       switch (opt) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 	case 'f': | 
					
						
							|  |  |  | 	  unset_function = 1; | 
					
						
							|  |  |  | 	  break; | 
					
						
							|  |  |  | 	case 'v': | 
					
						
							|  |  |  | 	  unset_variable = 1; | 
					
						
							|  |  |  | 	  break; | 
					
						
							| 
									
										
										
										
											2014-02-26 09:36:43 -05:00
										 |  |  | 	case 'n': | 
					
						
							|  |  |  | 	  nameref = 1; | 
					
						
							|  |  |  | 	  break; | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  | 	default: | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  | 	  builtin_usage (); | 
					
						
							|  |  |  | 	  return (EX_USAGE); | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   list = loptend; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   if (unset_function && unset_variable) | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2004-07-27 13:29:18 +00:00
										 |  |  |       builtin_error (_("cannot simultaneously unset a function and a variable")); | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  |       return (EXECUTION_FAILURE); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2014-02-26 09:36:43 -05:00
										 |  |  |   else if (unset_function && nameref) | 
					
						
							|  |  |  |     nameref = 0; | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |   while (list) | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  |       SHELL_VAR *var; | 
					
						
							|  |  |  |       int tem; | 
					
						
							|  |  |  | #if defined (ARRAY_VARS) | 
					
						
							|  |  |  |       char *t; | 
					
						
							|  |  |  | #endif | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  |       name = list->word->word; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  | #if defined (ARRAY_VARS) | 
					
						
							| 
									
										
										
										
											2001-11-13 17:56:06 +00:00
										 |  |  |       unset_array = 0; | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  |       if (!unset_function && valid_array_reference (name)) | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  | 	  t = strchr (name, '['); | 
					
						
							|  |  |  | 	  *t++ = '\0'; | 
					
						
							|  |  |  | 	  unset_array++; | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  | #endif | 
					
						
							| 
									
										
										
										
											2014-02-26 09:36:43 -05:00
										 |  |  |       /* Get error checking out of the way first.  The low-level functions | 
					
						
							|  |  |  | 	 just perform the unset, relying on the caller to verify. */ | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											1998-04-17 19:52:44 +00:00
										 |  |  |       /* Bash allows functions with names which are not valid identifiers | 
					
						
							|  |  |  | 	 to be created when not in posix mode, so check only when in posix | 
					
						
							|  |  |  | 	 mode when unsetting a function. */ | 
					
						
							|  |  |  |       if (((unset_function && posixly_correct) || !unset_function) && legal_identifier (name) == 0) | 
					
						
							| 
									
										
										
										
											2001-04-06 19:14:31 +00:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2002-07-17 14:10:11 +00:00
										 |  |  | 	  sh_invalidid (name); | 
					
						
							| 
									
										
										
										
											2001-04-06 19:14:31 +00:00
										 |  |  | 	  NEXT_VARIABLE (); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											1997-06-05 14:59:13 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-26 09:36:43 -05:00
										 |  |  |       /* Only search for functions here if -f supplied. */ | 
					
						
							|  |  |  |       var = unset_function ? find_function (name) | 
					
						
							|  |  |  | 			   : (nameref ? find_variable_last_nameref (name) : find_variable (name)); | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-26 09:36:43 -05:00
										 |  |  |       /* Some variables (but not functions yet) cannot be unset, period. */ | 
					
						
							|  |  |  |       if (var && unset_function == 0 && non_unsettable_p (var)) | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2004-07-27 13:29:18 +00:00
										 |  |  | 	  builtin_error (_("%s: cannot unset"), name); | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  | 	  NEXT_VARIABLE (); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-26 09:36:43 -05:00
										 |  |  |       /* Posix.2 says try variables first, then functions.  If we would | 
					
						
							|  |  |  | 	 find a function after unsuccessfully searching for a variable, | 
					
						
							|  |  |  | 	 note that we're acting on a function now as if -f were | 
					
						
							|  |  |  | 	 supplied.  The readonly check below takes care of it. */ | 
					
						
							|  |  |  |       if (var == 0 && unset_variable == 0 && unset_function == 0) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 	  if (var = find_function (name)) | 
					
						
							|  |  |  | 	    unset_function = 1; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  |       /* Posix.2 says that unsetting readonly variables is an error. */ | 
					
						
							|  |  |  |       if (var && readonly_p (var)) | 
					
						
							|  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2004-07-27 13:29:18 +00:00
										 |  |  | 	  builtin_error (_("%s: cannot unset: readonly %s"), | 
					
						
							| 
									
										
										
										
											2014-02-26 09:36:43 -05:00
										 |  |  | 			 var->name, unset_function ? "function" : "variable"); | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  | 	  NEXT_VARIABLE (); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  |       /* Unless the -f option is supplied, the name refers to a variable. */ | 
					
						
							|  |  |  | #if defined (ARRAY_VARS) | 
					
						
							|  |  |  |       if (var && unset_array) | 
					
						
							|  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2009-01-12 13:36:28 +00:00
										 |  |  | 	  if (array_p (var) == 0 && assoc_p (var) == 0) | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  | 	    { | 
					
						
							| 
									
										
										
										
											2014-02-26 09:36:43 -05:00
										 |  |  | 	      builtin_error (_("%s: not an array variable"), var->name); | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  | 	      NEXT_VARIABLE (); | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  | 	    } | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  | 	  else | 
					
						
							| 
									
										
										
										
											2002-07-17 14:10:11 +00:00
										 |  |  | 	    { | 
					
						
							|  |  |  | 	      tem = unbind_array_element (var, t); | 
					
						
							|  |  |  | 	      if (tem == -1) | 
					
						
							|  |  |  | 		any_failed++; | 
					
						
							|  |  |  | 	    } | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  |       else | 
					
						
							|  |  |  | #endif /* ARRAY_VARS */ | 
					
						
							| 
									
										
										
										
											2014-02-26 09:36:43 -05:00
										 |  |  |       tem = unset_function ? unbind_func (name) : (nameref ? unbind_nameref (name) : unbind_variable (name)); | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-26 09:36:43 -05:00
										 |  |  |       /* This is what Posix.2 says:  ``If neither -f nor -v | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  | 	 is specified, the name refers to a variable; if a variable by | 
					
						
							|  |  |  | 	 that name does not exist, a function by that name, if any, | 
					
						
							|  |  |  | 	 shall be unset.'' */ | 
					
						
							| 
									
										
										
										
											2014-02-26 09:36:43 -05:00
										 |  |  |       if (tem == -1 && unset_function == 0 && unset_variable == 0) | 
					
						
							| 
									
										
										
										
											2002-07-17 14:10:11 +00:00
										 |  |  | 	tem = unbind_func (name); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       /* SUSv3, POSIX.1-2001 say:  ``Unsetting a variable or function that | 
					
						
							|  |  |  | 	 was not previously set shall not be considered an error.'' */ | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-07-17 14:10:11 +00:00
										 |  |  |       if (unset_function == 0) | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  | 	stupidly_hack_special_variables (name); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  |       list = list->next; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  |   return (any_failed ? EXECUTION_FAILURE : EXECUTION_SUCCESS); | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  | } |