builtin
Execute commands as shell builtins
TLDR
Run a shell builtin
SYNOPSIS
builtin [name [arg…]]
PARAMETERS
name
Name of the shell built-in command to execute
arg…
Arguments passed to the specified built-in
DESCRIPTION
The builtin command is a Bash shell built-in utility that enables explicit execution of shell built-in commands or enumeration of all available built-ins. Invoked without arguments, it prints the names of all shell built-ins, one per line, aiding in discovery of internal shell commands like cd, echo, and read.
With a specified name and optional args, builtin runs the named built-in, ignoring any external executable with the same name in $PATH. This ensures use of efficient shell internals, avoiding process forking. For instance, builtin test -f /etc/passwd uses the shell's test over /usr/bin/test.
Built-ins run in the current shell context, accessing variables and features directly. This command is vital in scripts to prevent shadowing by external tools, enhancing portability and performance. It returns the exit status of the executed built-in or 0 if listing or invalid name.
CAVEATS
builtin silently succeeds (exit 0) if name is not a built-in; no error. Does not affect aliases, functions, or keywords. Bash-specific; behavior varies in other shells like dash.
EXAMPLES
builtin
Lists all built-ins (e.g., alias, cd, echo).
builtin pwd
Runs shell pwd, not external.
type -t test && builtin test -f file
Confirms and uses builtin test.
HISTORY
Introduced in Bash 1.0 (1989), mirroring Bourne shell concepts. Minimal changes across versions; Bash 4+ improved integration with coproc and other builtins.


