| 1 | This file is set.def, from which is created set.c.
|
|---|
| 2 | It implements the "set" and "unset" builtins in Bash.
|
|---|
| 3 |
|
|---|
| 4 | Copyright (C) 1987-2004 Free Software Foundation, Inc.
|
|---|
| 5 |
|
|---|
| 6 | This file is part of GNU Bash, the Bourne Again SHell.
|
|---|
| 7 |
|
|---|
| 8 | Bash is free software; you can redistribute it and/or modify it under
|
|---|
| 9 | the terms of the GNU General Public License as published by the Free
|
|---|
| 10 | Software Foundation; either version 2, or (at your option) any later
|
|---|
| 11 | version.
|
|---|
| 12 |
|
|---|
| 13 | Bash is distributed in the hope that it will be useful, but WITHOUT ANY
|
|---|
| 14 | WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|---|
| 15 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|---|
| 16 | for more details.
|
|---|
| 17 |
|
|---|
| 18 | You should have received a copy of the GNU General Public License along
|
|---|
| 19 | with Bash; see the file COPYING. If not, write to the Free Software
|
|---|
| 20 | Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA.
|
|---|
| 21 |
|
|---|
| 22 | $PRODUCES set.c
|
|---|
| 23 |
|
|---|
| 24 | #include <config.h>
|
|---|
| 25 |
|
|---|
| 26 | #if defined (HAVE_UNISTD_H)
|
|---|
| 27 | # ifdef _MINIX
|
|---|
| 28 | # include <sys/types.h>
|
|---|
| 29 | # endif
|
|---|
| 30 | # include <unistd.h>
|
|---|
| 31 | #endif
|
|---|
| 32 |
|
|---|
| 33 | #include <stdio.h>
|
|---|
| 34 |
|
|---|
| 35 | #include "../bashansi.h"
|
|---|
| 36 | #include "../bashintl.h"
|
|---|
| 37 |
|
|---|
| 38 | #include "../shell.h"
|
|---|
| 39 | #include "../flags.h"
|
|---|
| 40 | #include "common.h"
|
|---|
| 41 | #include "bashgetopt.h"
|
|---|
| 42 |
|
|---|
| 43 | #if defined (READLINE)
|
|---|
| 44 | # include "../input.h"
|
|---|
| 45 | # include "../bashline.h"
|
|---|
| 46 | # include <readline/readline.h>
|
|---|
| 47 | #endif
|
|---|
| 48 |
|
|---|
| 49 | #if defined (HISTORY)
|
|---|
| 50 | # include "../bashhist.h"
|
|---|
| 51 | #endif
|
|---|
| 52 |
|
|---|
| 53 | extern int posixly_correct, ignoreeof, eof_encountered_limit;
|
|---|
| 54 | #if defined (HISTORY)
|
|---|
| 55 | extern int dont_save_function_defs;
|
|---|
| 56 | #endif
|
|---|
| 57 | #if defined (READLINE)
|
|---|
| 58 | extern int no_line_editing;
|
|---|
| 59 | #endif /* READLINE */
|
|---|
| 60 |
|
|---|
| 61 | $BUILTIN set
|
|---|
| 62 | $FUNCTION set_builtin
|
|---|
| 63 | $SHORT_DOC set [--abefhkmnptuvxBCHP] [-o option] [arg ...]
|
|---|
| 64 | -a Mark variables which are modified or created for export.
|
|---|
| 65 | -b Notify of job termination immediately.
|
|---|
| 66 | -e Exit immediately if a command exits with a non-zero status.
|
|---|
| 67 | -f Disable file name generation (globbing).
|
|---|
| 68 | -h Remember the location of commands as they are looked up.
|
|---|
| 69 | -k All assignment arguments are placed in the environment for a
|
|---|
| 70 | command, not just those that precede the command name.
|
|---|
| 71 | -m Job control is enabled.
|
|---|
| 72 | -n Read commands but do not execute them.
|
|---|
| 73 | -o option-name
|
|---|
| 74 | Set the variable corresponding to option-name:
|
|---|
| 75 | allexport same as -a
|
|---|
| 76 | braceexpand same as -B
|
|---|
| 77 | #if defined (READLINE)
|
|---|
| 78 | emacs use an emacs-style line editing interface
|
|---|
| 79 | #endif /* READLINE */
|
|---|
| 80 | errexit same as -e
|
|---|
| 81 | errtrace same as -E
|
|---|
| 82 | functrace same as -T
|
|---|
| 83 | hashall same as -h
|
|---|
| 84 | #if defined (BANG_HISTORY)
|
|---|
| 85 | histexpand same as -H
|
|---|
| 86 | #endif /* BANG_HISTORY */
|
|---|
| 87 | #if defined (HISTORY)
|
|---|
| 88 | history enable command history
|
|---|
| 89 | #endif
|
|---|
| 90 | ignoreeof the shell will not exit upon reading EOF
|
|---|
| 91 | interactive-comments
|
|---|
| 92 | allow comments to appear in interactive commands
|
|---|
| 93 | keyword same as -k
|
|---|
| 94 | monitor same as -m
|
|---|
| 95 | noclobber same as -C
|
|---|
| 96 | noexec same as -n
|
|---|
| 97 | noglob same as -f
|
|---|
| 98 | nolog currently accepted but ignored
|
|---|
| 99 | notify same as -b
|
|---|
| 100 | nounset same as -u
|
|---|
| 101 | onecmd same as -t
|
|---|
| 102 | physical same as -P
|
|---|
| 103 | pipefail the return value of a pipeline is the status of
|
|---|
| 104 | the last command to exit with a non-zero status,
|
|---|
| 105 | or zero if no command exited with a non-zero status
|
|---|
| 106 | posix change the behavior of bash where the default
|
|---|
| 107 | operation differs from the 1003.2 standard to
|
|---|
| 108 | match the standard
|
|---|
| 109 | privileged same as -p
|
|---|
| 110 | verbose same as -v
|
|---|
| 111 | #if defined (READLINE)
|
|---|
| 112 | vi use a vi-style line editing interface
|
|---|
| 113 | #endif /* READLINE */
|
|---|
| 114 | xtrace same as -x
|
|---|
| 115 | -p Turned on whenever the real and effective user ids do not match.
|
|---|
| 116 | Disables processing of the $ENV file and importing of shell
|
|---|
| 117 | functions. Turning this option off causes the effective uid and
|
|---|
| 118 | gid to be set to the real uid and gid.
|
|---|
| 119 | -t Exit after reading and executing one command.
|
|---|
| 120 | -u Treat unset variables as an error when substituting.
|
|---|
| 121 | -v Print shell input lines as they are read.
|
|---|
| 122 | -x Print commands and their arguments as they are executed.
|
|---|
| 123 | #if defined (BRACE_EXPANSION)
|
|---|
| 124 | -B the shell will perform brace expansion
|
|---|
| 125 | #endif /* BRACE_EXPANSION */
|
|---|
| 126 | -C If set, disallow existing regular files to be overwritten
|
|---|
| 127 | by redirection of output.
|
|---|
| 128 | -E If set, the ERR trap is inherited by shell functions.
|
|---|
| 129 | #if defined (BANG_HISTORY)
|
|---|
| 130 | -H Enable ! style history substitution. This flag is on
|
|---|
| 131 | by default when the shell is interactive.
|
|---|
| 132 | #endif /* BANG_HISTORY */
|
|---|
| 133 | -P If set, do not follow symbolic links when executing commands
|
|---|
| 134 | such as cd which change the current directory.
|
|---|
| 135 | -T If set, the DEBUG trap is inherited by shell functions.
|
|---|
| 136 | - Assign any remaining arguments to the positional parameters.
|
|---|
| 137 | The -x and -v options are turned off.
|
|---|
| 138 |
|
|---|
| 139 | Using + rather than - causes these flags to be turned off. The
|
|---|
| 140 | flags can also be used upon invocation of the shell. The current
|
|---|
| 141 | set of flags may be found in $-. The remaining n ARGs are positional
|
|---|
| 142 | parameters and are assigned, in order, to $1, $2, .. $n. If no
|
|---|
| 143 | ARGs are given, all shell variables are printed.
|
|---|
| 144 | $END
|
|---|
| 145 |
|
|---|
| 146 | typedef int setopt_set_func_t __P((int, char *));
|
|---|
| 147 | typedef int setopt_get_func_t __P((char *));
|
|---|
| 148 |
|
|---|
| 149 | static void print_minus_o_option __P((char *, int, int));
|
|---|
| 150 | static void print_all_shell_variables __P((void));
|
|---|
| 151 |
|
|---|
| 152 | static int set_ignoreeof __P((int, char *));
|
|---|
| 153 | static int set_posix_mode __P((int, char *));
|
|---|
| 154 |
|
|---|
| 155 | #if defined (READLINE)
|
|---|
| 156 | static int set_edit_mode __P((int, char *));
|
|---|
| 157 | static int get_edit_mode __P((char *));
|
|---|
| 158 | #endif
|
|---|
| 159 |
|
|---|
| 160 | #if defined (HISTORY)
|
|---|
| 161 | static int bash_set_history __P((int, char *));
|
|---|
| 162 | #endif
|
|---|
| 163 |
|
|---|
| 164 | static char *on = "on";
|
|---|
| 165 | static char *off = "off";
|
|---|
| 166 |
|
|---|
| 167 | /* A struct used to match long options for set -o to the corresponding
|
|---|
| 168 | option letter or internal variable. The functions can be called to
|
|---|
| 169 | dynamically generate values. */
|
|---|
| 170 | struct {
|
|---|
| 171 | char *name;
|
|---|
| 172 | int letter;
|
|---|
| 173 | int *variable;
|
|---|
| 174 | setopt_set_func_t *set_func;
|
|---|
| 175 | setopt_get_func_t *get_func;
|
|---|
| 176 | } o_options[] = {
|
|---|
| 177 | { "allexport", 'a', (int *)NULL, (setopt_set_func_t *)NULL, (setopt_get_func_t *)NULL },
|
|---|
| 178 | #if defined (BRACE_EXPANSION)
|
|---|
| 179 | { "braceexpand",'B', (int *)NULL, (setopt_set_func_t *)NULL, (setopt_get_func_t *)NULL },
|
|---|
| 180 | #endif
|
|---|
| 181 | #if defined (READLINE)
|
|---|
| 182 | { "emacs", '\0', (int *)NULL, set_edit_mode, get_edit_mode },
|
|---|
| 183 | #endif
|
|---|
| 184 | { "errexit", 'e', (int *)NULL, (setopt_set_func_t *)NULL, (setopt_get_func_t *)NULL },
|
|---|
| 185 | { "errtrace", 'E', (int *)NULL, (setopt_set_func_t *)NULL, (setopt_get_func_t *)NULL },
|
|---|
| 186 | { "functrace", 'T', (int *)NULL, (setopt_set_func_t *)NULL, (setopt_get_func_t *)NULL },
|
|---|
| 187 | { "hashall", 'h', (int *)NULL, (setopt_set_func_t *)NULL, (setopt_get_func_t *)NULL },
|
|---|
| 188 | #if defined (BANG_HISTORY)
|
|---|
| 189 | { "histexpand", 'H', (int *)NULL, (setopt_set_func_t *)NULL, (setopt_get_func_t *)NULL },
|
|---|
| 190 | #endif /* BANG_HISTORY */
|
|---|
| 191 | #if defined (HISTORY)
|
|---|
| 192 | { "history", '\0', &remember_on_history, bash_set_history, (setopt_get_func_t *)NULL },
|
|---|
| 193 | #endif
|
|---|
| 194 | { "ignoreeof", '\0', &ignoreeof, set_ignoreeof, (setopt_get_func_t *)NULL },
|
|---|
| 195 | { "interactive-comments", '\0', &interactive_comments, (setopt_set_func_t *)NULL, (setopt_get_func_t *)NULL },
|
|---|
| 196 | { "keyword", 'k', (int *)NULL, (setopt_set_func_t *)NULL, (setopt_get_func_t *)NULL },
|
|---|
| 197 | { "monitor", 'm', (int *)NULL, (setopt_set_func_t *)NULL, (setopt_get_func_t *)NULL },
|
|---|
| 198 | { "noclobber", 'C', (int *)NULL, (setopt_set_func_t *)NULL, (setopt_get_func_t *)NULL },
|
|---|
| 199 | { "noexec", 'n', (int *)NULL, (setopt_set_func_t *)NULL, (setopt_get_func_t *)NULL },
|
|---|
| 200 | { "noglob", 'f', (int *)NULL, (setopt_set_func_t *)NULL, (setopt_get_func_t *)NULL },
|
|---|
| 201 | #if defined (HISTORY)
|
|---|
|
|---|