1 This file is alias.def, from which is created alias.c
2 It implements the builtins "alias" and "unalias" 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.
23 $FUNCTION alias_builtin
26 $SHORT_DOC alias [ name[=value] ... ]
27 `alias' with no arguments prints the list of aliases in the form
28 NAME=VALUE on standard output. An alias is defined for each NAME
29 whose VALUE is given. A trailing space in VALUE causes the next
30 word to be checked for alias substitution. Alias returns true
31 unless a NAME is given for which no alias has been defined.
34 #include "../config.h"
38 # include "../shell.h"
39 # include "../alias.h"
42 extern int interactive;
43 static void print_alias ();
45 /* Hack the alias command in a Korn shell way. */
57 return (EXECUTION_FAILURE);
59 alias_list = all_aliases ();
62 return (EXECUTION_FAILURE);
64 for (i = 0; alias_list[i]; i++)
65 print_alias (alias_list[i]);
67 free (alias_list); /* XXX - Do not free the strings. */
73 register char *value, *name = list->word->word;
76 for (offset = 0; name[offset] && name[offset] != '='; offset++)
79 if (offset && name[offset] == '=')
82 value = name + offset + 1;
84 add_alias (name, value);
88 ASSOC *t = find_alias (name);
94 builtin_error ("`%s' not found", name);
102 return (EXECUTION_FAILURE);
104 return (EXECUTION_SUCCESS);
109 $FUNCTION unalias_builtin
111 $SHORT_DOC unalias [-a] [name ...]
112 Remove NAMEs from the list of defined aliases. If the -a option is given,
113 then remove all alias definitions.
117 /* Remove aliases named in LIST from the aliases database. */
118 unalias_builtin (list)
119 register WORD_LIST *list;
121 register ASSOC *alias;
124 while (list && *list->word->word == '-')
126 register char *word = list->word->word;
128 if (ISOPTION (word, 'a'))
130 delete_all_aliases ();
133 else if (ISOPTION (word, '-'))
141 return (EXECUTION_FAILURE);
147 alias = find_alias (list->word->word);
150 remove_alias (alias->name);
154 builtin_error ("`%s' not an alias", list->word->word);
163 return (EXECUTION_FAILURE);
165 return (EXECUTION_SUCCESS);
168 /* Output ALIAS in such a way as to allow it to be read back in. */
173 char *value = single_quote (alias->value);
175 printf ("alias %s=%s\n", alias->name, value);