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. */
27 /* **************************************************************** */
29 /* The Standard Sh Flags. */
31 /* **************************************************************** */
33 /* Non-zero means automatically mark variables which are modified or created
34 as auto export variables. */
35 int mark_modified_vars = 0;
37 /* Non-zero causes asynchronous job notification. Otherwise, job state
38 notification only takes place just before a primary prompt is printed. */
39 int asynchronous_notification = 0;
41 /* Non-zero means exit immediately if a command exits with a non-zero
43 int exit_immediately_on_error = 0;
45 /* Non-zero means disable filename globbing. */
46 int disallow_filename_globbing = 0;
48 /* Non-zero means to locate and remember function commands as functions are
49 defined. Function commands are normally located when the function is
51 int locate_commands_in_functions = 0;
53 /* Non-zero means that all keyword arguments are placed into the environment
54 for a command, not just those that appear on the line before the command
56 int place_keywords_in_env = 0;
58 /* Non-zero means read commands, but don't execute tham. This is useful
59 for debugging shell scripts that should do something hairy and possibly
61 int read_but_dont_execute = 0;
63 /* Non-zero means end of file is after one command. */
64 int just_one_command = 0;
66 /* Non-zero means don't overwrite existing files while doing redirections. */
69 /* Non-zero means trying to get the value of $i where $i is undefined
70 causes an error, instead of a null substitution. */
71 int unbound_vars_is_error = 0;
73 /* Non-zero means type out input lines after you read them. */
74 int echo_input_at_read = 0;
76 /* Non-zero means type out the command definition after reading, but
78 int echo_command_at_execute = 0;
80 /* Non-zero means turn on the job control features. */
83 /* Non-zero means this shell is interactive, even if running under a
85 int forced_interactive = 0;
87 /* By default, follow the symbolic links as if they were real directories
88 while hacking the `cd' command. This means that `cd ..' moves up in
89 the string of symbolic links that make up the current directory, instead
90 of the absolute directory. The shell variable `nolinks' also controls
92 int no_symbolic_links = 0;
94 /* **************************************************************** */
96 /* Non-Standard Flags Follow Here. */
98 /* **************************************************************** */
101 /* Non-zero means do lexical scoping in the body of a FOR command. */
102 int lexical_scoping = 0;
104 /* Non-zero means no such thing as invisible variables. */
105 int no_invisible_vars = 0;
107 /* Non-zero means don't look up or remember command names in a hash table, */
108 int hashing_disabled = 0;
110 #if defined (BANG_HISTORY)
111 /* Non-zero means that we are doing history expansion. The default.
112 This means !22 gets the 22nd line of history. */
113 int history_expansion = 1;
114 #endif /* BANG_HISTORY */
116 /* Non-zero means that we allow comments to appear in interactive commands. */
117 #if defined (INTERACTIVE_COMMENTS)
118 int interactive_comments = 1;
120 int interactive_comments = 0;
121 #endif /* INTERACTIVE_COMMENTS */
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 /* **************************************************************** */
138 /* The Flags ALIST. */
140 /* **************************************************************** */
142 struct flags_alist shell_flags[] = {
143 /* Standard sh flags. */
144 { 'a', &mark_modified_vars },
145 #if defined (JOB_CONTROL)
146 { 'b', &asynchronous_notification },
147 #endif /* JOB_CONTROL */
148 { 'e', &exit_immediately_on_error },
149 { 'f', &disallow_filename_globbing },
150 { 'h', &locate_commands_in_functions }, /* Oh, yeah, good mnemonic. */
151 { 'i', &forced_interactive },
152 { 'k', &place_keywords_in_env },
153 #if defined (JOB_CONTROL)
154 { 'm', &jobs_m_flag },
155 #endif /* JOB_CONTROL */
156 { 'n', &read_but_dont_execute },
157 { 'p', &privileged_mode },
158 #if defined (RESTRICTED_SHELL)
159 { 'r', &restricted },
160 #endif /* RESTRICTED_SHELL */
161 { 't', &just_one_command },
162 { 'u', &unbound_vars_is_error },
163 { 'v', &echo_input_at_read },
164 { 'x', &echo_command_at_execute },
167 /* New flags that control non-standard things. */
168 { 'l', &lexical_scoping },
169 { 'I', &no_invisible_vars },
171 /* I want `h', but locate_commands_in_functions has it. Great. */
172 { 'd', &hashing_disabled },
174 { 'P', &no_symbolic_links },
176 #if defined (BANG_HISTORY)
177 /* Once again, we don't have the right mnemonic. */
178 { 'H', &history_expansion },
179 #endif /* BANG_HISTORY */
184 #define NUM_SHELL_FLAGS (sizeof (shell_flags) / sizeof (struct flags_alist))
191 while (shell_flags[i].name)
193 if (shell_flags[i].name == name)
194 return (shell_flags[i].value);
197 return (FLAG_UNKNOWN);
200 /* Change the state of a flag, and return it's original value, or return
201 FLAG_ERROR if there is no flag called NAME. ON_OR_OFF should be one
202 of FLAG_ON or FLAG_OFF. */
204 change_flag (flag, on_or_off)
208 int *value = find_flag (flag);
211 #if defined (RESTRICTED_SHELL)
212 /* Don't allow "set +r" in a shell which is `restricted'. */
213 if (restricted && flag == 'r' && on_or_off == FLAG_OFF)
215 #endif /* RESTRICTED_SHELL */
217 if (value == (int *)FLAG_UNKNOWN)
222 if (on_or_off == FLAG_ON)
226 if (on_or_off == FLAG_OFF)
232 /* Special cases for a few flags. */
235 #if defined (JOB_CONTROL)
237 set_job_control (on_or_off == '-');
239 #endif /* JOB_CONTROL */
242 if (on_or_off == '+')
244 setuid (current_user.uid);
245 setgid (current_user.gid);
246 current_user.euid = current_user.uid;
247 current_user.egid = current_user.gid;
255 /* Return a string which is the names of all the currently
260 char *temp = (char *)xmalloc (1 + NUM_SHELL_FLAGS);
262 int i, string_index = 0;
264 for (i = 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';