1 /* flags.c -- Everything about flags except the `set' command. That
4 /* Copyright (C) 1987,1989 Free Software Foundation, Inc.
6 This file is part of GNU Bash, the Bourne Again SHell.
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 1, or (at your option) any later
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
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, 675 Mass Ave, Cambridge, MA 02139, USA. */
24 #if defined (HAVE_UNISTD_H)
31 #if defined (JOB_CONTROL)
32 extern int set_job_control ();
35 /* **************************************************************** */
37 /* The Standard Sh Flags. */
39 /* **************************************************************** */
41 /* Non-zero means automatically mark variables which are modified or created
42 as auto export variables. */
43 int mark_modified_vars = 0;
45 /* Non-zero causes asynchronous job notification. Otherwise, job state
46 notification only takes place just before a primary prompt is printed. */
47 int asynchronous_notification = 0;
49 /* Non-zero means exit immediately if a command exits with a non-zero
51 int exit_immediately_on_error = 0;
53 /* Non-zero means disable filename globbing. */
54 int disallow_filename_globbing = 0;
56 /* Non-zero means that all keyword arguments are placed into the environment
57 for a command, not just those that appear on the line before the command
59 int place_keywords_in_env = 0;
61 /* Non-zero means read commands, but don't execute them. This is useful
62 for debugging shell scripts that should do something hairy and possibly
64 int read_but_dont_execute = 0;
66 /* Non-zero means end of file is after one command. */
67 int just_one_command = 0;
69 /* Non-zero means don't overwrite existing files while doing redirections. */
72 /* Non-zero means trying to get the value of $i where $i is undefined
73 causes an error, instead of a null substitution. */
74 int unbound_vars_is_error = 0;
76 /* Non-zero means type out input lines after you read them. */
77 int echo_input_at_read = 0;
79 /* Non-zero means type out the command definition after reading, but
81 int echo_command_at_execute = 0;
83 /* Non-zero means turn on the job control features. */
86 /* Non-zero means this shell is interactive, even if running under a
88 int forced_interactive = 0;
90 /* By default, follow the symbolic links as if they were real directories
91 while hacking the `cd' command. This means that `cd ..' moves up in
92 the string of symbolic links that make up the current directory, instead
93 of the absolute directory. The shell variable `nolinks' also controls
95 int no_symbolic_links = 0;
97 /* **************************************************************** */
99 /* Non-Standard Flags Follow Here. */
101 /* **************************************************************** */
104 /* Non-zero means do lexical scoping in the body of a FOR command. */
105 int lexical_scoping = 0;
108 /* Non-zero means no such thing as invisible variables. */
109 int no_invisible_vars = 0;
111 /* Non-zero means look up and remember command names in a hash table, */
112 int hashing_enabled = 1;
114 #if defined (BANG_HISTORY)
115 /* Non-zero means that we are doing history expansion. The default.
116 This means !22 gets the 22nd line of history. */
117 int history_expansion = 1;
118 #endif /* BANG_HISTORY */
120 /* Non-zero means that we allow comments to appear in interactive commands. */
121 int interactive_comments = 1;
123 #if defined (RESTRICTED_SHELL)
124 /* Non-zero means that this shell is `restricted'. A restricted shell
125 disallows: changing directories, command or path names containing `/',
126 unsetting or resetting the values of $PATH and $SHELL, and any type of
127 output redirection. */
129 #endif /* RESTRICTED_SHELL */
131 /* Non-zero means that this shell is running in `privileged' mode. This
132 mode is entered on startup if the real and effective uids or gids
134 int privileged_mode = 0;
136 #if defined (BRACE_EXPANSION)
137 /* Zero means to disable brace expansion: foo{a,b} -> fooa foob */
138 int brace_expansion = 1;
141 /* **************************************************************** */
143 /* The Flags ALIST. */
145 /* **************************************************************** */
147 struct flags_alist shell_flags[] = {
148 /* Standard sh flags. */
149 { 'a', &mark_modified_vars },
150 #if defined (JOB_CONTROL)
151 { 'b', &asynchronous_notification },
152 #endif /* JOB_CONTROL */
153 { 'e', &exit_immediately_on_error },
154 { 'f', &disallow_filename_globbing },
155 { 'h', &hashing_enabled },
156 { 'i', &forced_interactive },
157 { 'k', &place_keywords_in_env },
158 #if defined (JOB_CONTROL)
159 { 'm', &jobs_m_flag },
160 #endif /* JOB_CONTROL */
161 { 'n', &read_but_dont_execute },
162 { 'p', &privileged_mode },
163 #if defined (RESTRICTED_SHELL)
164 { 'r', &restricted },
165 #endif /* RESTRICTED_SHELL */
166 { 't', &just_one_command },
167 { 'u', &unbound_vars_is_error },
168 { 'v', &echo_input_at_read },
169 { 'x', &echo_command_at_execute },
172 /* New flags that control non-standard things. */
174 { 'l', &lexical_scoping },
176 { 'I', &no_invisible_vars },
178 { 'P', &no_symbolic_links },
180 #if defined (BRACE_EXPANSION)
181 { 'B', &brace_expansion },
184 #if defined (BANG_HISTORY)
185 { 'H', &history_expansion },
186 #endif /* BANG_HISTORY */
191 #define NUM_SHELL_FLAGS (sizeof (shell_flags) / sizeof (struct flags_alist))
198 for (i = 0; shell_flags[i].name; i++)
200 if (shell_flags[i].name == name)
201 return (shell_flags[i].value);
203 return (FLAG_UNKNOWN);
206 /* Change the state of a flag, and return it's original value, or return
207 FLAG_ERROR if there is no flag called NAME. ON_OR_OFF should be one
208 of FLAG_ON or FLAG_OFF. */
210 change_flag (flag, on_or_off)
214 int *value, old_value;
216 value = find_flag (flag);
218 #if defined (RESTRICTED_SHELL)
219 /* Don't allow "set +r" in a shell which is `restricted'. */
220 if (restricted && flag == 'r' && on_or_off == FLAG_OFF)
222 #endif /* RESTRICTED_SHELL */
224 if (value == (int *)FLAG_UNKNOWN)
229 if (on_or_off == FLAG_ON)
231 else if (on_or_off == FLAG_OFF)
236 /* Special cases for a few flags. */
239 #if defined (JOB_CONTROL)
241 set_job_control (on_or_off == '-');
243 #endif /* JOB_CONTROL */
246 if (on_or_off == '+')
247 disable_priv_mode ();
255 /* Return a string which is the names of all the currently
263 temp = xmalloc (1 + NUM_SHELL_FLAGS);
264 for (i = string_index = 0; shell_flags[i].name; i++)
265 if (*(shell_flags[i].value))
266 temp[string_index++] = shell_flags[i].name;
268 temp[string_index] = '\0';