1 This file is enable.def, from which is created enable.c.
2 It implements the builtin "enable" in Bash.
4 Copyright (C) 1987, 1989, 1991 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.
25 $FUNCTION enable_builtin
26 $SHORT_DOC enable [-n] [name ...]
27 Enable and disable builtin shell commands. This allows
28 you to use a disk command which has the same name as a shell
29 builtin. If -n is used, the NAMEs become disabled. Otherwise
30 NAMEs are enabled. For example, to use the `test' found on your
31 path instead of the shell builtin version, you type `enable -n test'.
35 #include "../builtins.h"
41 static int enable_shell_command ();
42 static void list_some_builtins ();
44 /* Enable/disable shell commands present in LIST. If list is not specified,
45 then print out a list of shell commands showing which are enabled and
46 which are disabled. */
50 int result = 0, any_failed = 0;
53 disable_p = all_p = 0;
55 while (list && list->word->word && list->word->word[0] == '-')
57 char *arg = list->word->word;
61 if (ISOPTION (arg, 'n'))
63 else if (arg[1] == 'a' && (arg[2] == 0 || strcmp (arg + 2, "ll") == 0))
65 else if (ISOPTION (arg, '-'))
70 return (EXECUTION_FAILURE);
79 filter = ENABLED | DISABLED;
85 list_some_builtins (filter);
91 result = enable_shell_command (list->word->word, disable_p);
95 builtin_error ("%s: not a shell builtin", list->word->word);
101 return (any_failed ? EXECUTION_FAILURE : EXECUTION_SUCCESS);
104 /* List some builtins.
105 FILTER is a mask with two slots: ENABLED and DISABLED. */
107 list_some_builtins (filter)
112 for (i = 0; i < num_shell_builtins; i++)
114 if (!shell_builtins[i].function)
117 if ((filter & ENABLED) &&
118 (shell_builtins[i].flags & BUILTIN_ENABLED))
120 printf ("enable %s\n", shell_builtins[i].name);
122 else if ((filter & DISABLED) &&
123 ((shell_builtins[i].flags & BUILTIN_ENABLED) == 0))
125 printf ("enable -n %s\n", shell_builtins[i].name);
130 /* Enable the shell command NAME. If DISABLE_P is non-zero, then
131 disable NAME instead. */
133 enable_shell_command (name, disable_p)
140 for (i = 0; i < num_shell_builtins; i++)
142 if (!shell_builtins[i].function)
145 if (STREQ (name, shell_builtins[i].name))
150 shell_builtins[i].flags &= ~BUILTIN_ENABLED;
152 shell_builtins[i].flags |= BUILTIN_ENABLED;