blob: 3e765e4108b38312fd3351673b6fde8cd84abfa2 [file] [log] [blame]
Jari Aalto726f6381996-08-26 18:22:31 +00001This file is builtin.def, from which is created builtin.c.
2It implements the builtin "builtin" in Bash.
3
Jari Aalto31859422009-01-12 13:36:28 +00004Copyright (C) 1987-2009 Free Software Foundation, Inc.
Jari Aalto726f6381996-08-26 18:22:31 +00005
6This file is part of GNU Bash, the Bourne Again SHell.
7
Jari Aalto31859422009-01-12 13:36:28 +00008Bash is free software: you can redistribute it and/or modify
9it under the terms of the GNU General Public License as published by
10the Free Software Foundation, either version 3 of the License, or
11(at your option) any later version.
Jari Aalto726f6381996-08-26 18:22:31 +000012
Jari Aalto31859422009-01-12 13:36:28 +000013Bash is distributed in the hope that it will be useful,
14but WITHOUT ANY WARRANTY; without even the implied warranty of
15MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16GNU General Public License for more details.
Jari Aalto726f6381996-08-26 18:22:31 +000017
Jari Aalto31859422009-01-12 13:36:28 +000018You should have received a copy of the GNU General Public License
19along with Bash. If not, see <http://www.gnu.org/licenses/>.
Jari Aalto726f6381996-08-26 18:22:31 +000020
21$PRODUCES builtin.c
22
23$BUILTIN builtin
24$FUNCTION builtin_builtin
25$SHORT_DOC builtin [shell-builtin [arg ...]]
Jari Aalto31859422009-01-12 13:36:28 +000026Execute shell builtins.
27
28Execute SHELL-BUILTIN with arguments ARGs without performing command
29lookup. This is useful when you wish to reimplement a shell builtin
30as a shell function, but need to execute the builtin within the function.
31
32Exit Status:
33Returns the exit status of SHELL-BUILTIN, or false if SHELL-BUILTIN is
34not a shell builtin..
Jari Aalto726f6381996-08-26 18:22:31 +000035$END
Jari Aaltoccc6cda1996-12-23 17:02:34 +000036#include <config.h>
37
38#if defined (HAVE_UNISTD_H)
Jari Aaltocce855b1998-04-17 19:52:44 +000039# ifdef _MINIX
40# include <sys/types.h>
41# endif
Jari Aaltoccc6cda1996-12-23 17:02:34 +000042# include <unistd.h>
43#endif
Jari Aalto726f6381996-08-26 18:22:31 +000044
45#include "../shell.h"
Jari Aalto726f6381996-08-26 18:22:31 +000046#include "common.h"
Jari Aalto7117c2d2002-07-17 14:10:11 +000047#include "bashgetopt.h"
Jari Aalto726f6381996-08-26 18:22:31 +000048
49extern char *this_command_name;
50
51/* Run the command mentioned in list directly, without going through the
52 normal alias/function/builtin/filename lookup process. */
Jari Aaltoccc6cda1996-12-23 17:02:34 +000053int
Jari Aalto726f6381996-08-26 18:22:31 +000054builtin_builtin (list)
55 WORD_LIST *list;
56{
Jari Aaltof73dda02001-11-13 17:56:06 +000057 sh_builtin_func_t *function;
Jari Aalto726f6381996-08-26 18:22:31 +000058 register char *command;
59
Jari Aalto7117c2d2002-07-17 14:10:11 +000060 if (no_options (list))
61 return (EX_USAGE);
62 list = loptend; /* skip over possible `--' */
63
64 if (list == 0)
Jari Aalto726f6381996-08-26 18:22:31 +000065 return (EXECUTION_SUCCESS);
66
Jari Aalto7117c2d2002-07-17 14:10:11 +000067 command = list->word->word;
Jari Aalto726f6381996-08-26 18:22:31 +000068#if defined (DISABLED_BUILTINS)
69 function = builtin_address (command);
70#else /* !DISABLED_BUILTINS */
71 function = find_shell_builtin (command);
72#endif /* !DISABLED_BUILTINS */
73
74 if (!function)
75 {
Jari Aaltob80f6442004-07-27 13:29:18 +000076 sh_notbuiltin (command);
Jari Aalto726f6381996-08-26 18:22:31 +000077 return (EXECUTION_FAILURE);
78 }
79 else
80 {
81 this_command_name = command;
82 list = list->next;
83 return ((*function) (list));
84 }
85}