Annotated edit history of
ShellBuiltinNotes version 5, including all changes.
View license author blame.
Rev |
Author |
# |
Line |
5 |
IanMcDonald |
1 |
In Unix, a shell builtin is a command or a function, called from a [Shell], that is executed directly in the shell itself, instead of an external executable program which the shell would load and execute. |
1 |
BenStaz |
2 |
|
|
|
3 |
!How can I tell if the command I am using is a shell builtin rather than an external program? |
|
|
4 |
|
|
|
5 |
*type <command_name> |
|
|
6 |
|
|
|
7 |
<verbatim> |
2 |
BenStaz |
8 |
$ type cd |
1 |
BenStaz |
9 |
cd is a shell builtin |
|
|
10 |
|
2 |
BenStaz |
11 |
$ type mkdir |
1 |
BenStaz |
12 |
mkdir is /bin/mkdir |
|
|
13 |
</verbatim> |
2 |
BenStaz |
14 |
|
|
|
15 |
!But I want to use an external program rather than a shell-builtin. |
|
|
16 |
|
|
|
17 |
If a command specified to the shell contains a slash ''/'', the shell will not execute a builtin command. Thus, while specifying ''echo'' causes a builtin command to be executed under shells that support the builtin echo command, specifying ''/bin/echo'' does not. |
|
|
18 |
|
|
|
19 |
!Why can I not use ''sudo <shell_builtin>'' ? |
|
|
20 |
|
4 |
BenStaz |
21 |
A shell builtin is not an executable file so sudo does not know about it. (obviously wont be found in any dirs in sudo's PATH). |
3 |
BenStaz |
22 |
You will need to use the command ''sudo -s'' to get a new shell with root privileges or alternatively you can do ''sudo bash -c "<shell_builtin>" ~[args~]''. |