What does the builtin command do in bash?

Solution 1:

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, let's say you defined a shell function named cd to print some extra status everytime you change directories. But you messed it up and now you can't change directories correctly. So now you can type builtin cd ~ to successfully cd back to your home directory without running your broken shell function.

And 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).

builtin shell-builtin [arguments]

    Execute  the  specified  shell builtin, passing it arguments, and
    return its exit status.  This is useful when defining a function
    whose name  is the  same as a shell builtin, retaining the
    functionality of the builtin within the function.  The cd builtin is
    commonly  redefined  this  way.

    The  return status is false if shell-builtin is not a shell builtin
    command.