The builtin commands in Bash can be extremely useful, but what does “builtin” itself actually do? Today’s SuperUser Q&A post has the answer to a curious reader’s question.
Today’s Question & Answer session comes to us courtesy of SuperUser—a subdivision of Stack Exchange, a community-driven grouping of Q&A web sites.
SuperUser reader lfalin wants to know what the builtin command in Bash does:
I know what a builtin command is, but what does builtin itself do? Executing which ls shows me /bin/ls, but executing which builtin returns nothing. man builtin just gives me a list of builtin commands, one of which is builtin. The rest of the man page explains what a builtin command is, but not what builtin itself is. builtin –help tells me builtin: usage: builtin [shell-builtin [arg …]], but still not what it does. Is it a part of Bash in a way that other builtin commands are not?
What does the builtin command in Bash do?
SuperUser contributor Spiff has the answer for us:
The builtin command makes sure you run the shell built-in version of the command rather than running another command with the same name.
For example, imagine you defined a shell function named cd to print some extra status every time you change directories, but you messed it up and now you cannot change directories correctly. So now you can type builtin cd ~ to successfully cd back to your home directory without running your broken shell function.
By the way, my copy of the Bash man page has a section called “SHELL BUILTIN COMMANDS”, and it defines the meaning of the builtin command in that section (transcribed below).
Have something to add to the explanation? Sound off in the comments. Want to read more answers from other tech-savvy Stack Exchange users? Check out the full discussion thread here.
- › ASUS’s New Wireless Mouse Can Hang On Your Bag
- › MSI Goes All-In on Intel 13th Gen Chips, RTX 4000 GPUs
- › Apple Is Rethinking the iPad’s Stage Manager Feature
- › Intel’s Arc A770 GPU is Like an RTX 3070 For Half the Price
- › How to Find Circular References in Microsoft Excel
- › How to Forward a Text Message on iPhone