The builtin
command is used to execute built-in commands that are part of the Bash shell. Built-in commands are commands that are built into the shell itself, rather than being separate executable files. The builtin
command is used to execute these commands directly from the shell, rather than having to call an external executable file.
Overview
The builtin
command is used to execute built-in commands in Bash. This command is typically used when you want to execute a built-in command that has the same name as an external command. When you type a command into the shell, Bash will first look for an external command with that name. If it doesn’t find one, it will then look for a built-in command with that name. If there is a built-in command with that name, you can use the builtin
command to execute it directly.
Syntax
builtin [option] [arguments]
Example
$ type cd
cd is a shell builtin
$ builtin cd /home/user/Documents
$ pwd
/home/user/Documents
In this example, we use the type
command to determine that cd
is a built-in command in Bash. We then use the builtin
command to execute the cd
command and change our current working directory to /home/user/Documents
.
Options
The builtin
command has the following options:
Option | Description |
---|---|
-d |
Delete a shell function. |
-e |
Exit immediately if a pipeline (which may consist of a single simple command), a subshell command enclosed in parentheses, or one of the commands executed as part of a command list enclosed by braces exits with a non-zero status. |
-f |
Load a function into memory, but do not execute it. |
-n |
Read commands but do not execute them. This may be used to check a shell script for syntax errors. |
-p |
Display a list of all built-in commands and their definitions. |
-r |
Remove the definition of each NAME from the list of shell functions. |
-s |
Read commands from the standard input and execute them. |
Troubleshooting tips
If you are having trouble executing a built-in command, make sure that you are using the correct syntax for the builtin
command. Also, be aware that some built-in commands may have different behavior than their external counterparts.
Notes
The builtin
command is only used to execute built-in commands in Bash. If you want to execute an external command, you should use the full path to the executable or include the executable in your shell’s PATH
variable.