Bash – Need for the `builtin` builtin

bashshell-builtin

What's the point of the builtin builtin when the command builtin has the exact same functionality when it comes to looking up builtins?

When making sure that a particular builtin is chosen over a function with the same name, builtin offers no additional value compared to command. One could argue that builtin is more explicit but still, I could only imagine that using command might be picked when one is not sure if some command is also available as a builtin.

Best Answer

builtin is not a standard utility.

The POSIX standard documentation says this in the Rationale section for the command utility:

The command utility is somewhat similar to the Eighth Edition shell builtin command, but since command also goes to the file system to search for utilities, the name builtin would not be intuitive.

The builtin utility is provided by bash for backward compatibility.

I note that dash, for example, does not implement builtin:

$ builtin printf 'hello\n'
/usr/local/bin/dash: 3: builtin: not found
Related Question