LinuxCommandLibrary

builtin

Execute a shell built-in command directly

TLDR

Run built-in command

$ builtin cd [/path]
copy
Check if command is built-in
$ type cd
copy

SYNOPSIS

builtin command [args]

DESCRIPTION

builtin forces the shell to run a built-in command even if a function or alias with the same name exists. It's a bash built-in command used to bypass shell functions and aliases to access the original built-in implementation.
The command is useful when functions or aliases shadow built-in commands.

USAGE

$ # Function shadows cd
cd() {
    echo "Going to $1"
    builtin cd "$1"
}

# Now 'cd' runs the function, but function uses builtin cd

# Direct builtin usage
builtin cd /tmp  # Bypasses any cd function
copy

COMMON BUILT-INS

- cd - Change directory
- echo - Print text
- read - Read input
- test - Conditional evaluation
- export - Set environment variables
- source - Execute script
- alias - Create aliases
- set - Set shell options

WORKFLOW

$ # Create function that wraps cd
cd() {
    echo "Changing to $1"
    builtin cd "$1" && ls
}

# Use the function
cd /tmp  # Prints message and lists directory

# Use built-in directly
builtin cd /tmp  # Just changes directory
copy

CAVEATS

Only works with shell built-in commands. No effect on external commands. Behavior varies between shells (bash, zsh, etc.). Not needed unless functions/aliases shadow built-ins.

HISTORY

builtin has been part of bash and other shells since the late 1980s to provide access to built-in commands when shadowed.

SEE ALSO

command(1), type(1), enable(1)

> TERMINAL_GEAR

Curated for the Linux community

Copied to clipboard

> TERMINAL_GEAR

Curated for the Linux community