Simple question, really...
Builtin?
What happens when you run: builtin?
The return type from echo $? is 0.
Which means that the command has most likely run successfully.
So, what does running builtin accomplish?
Simple question, really...
What happens when you run: builtin?
The return type from echo $? is 0.
Which means that the command has most likely run successfully.
So, what does running builtin accomplish?
This is useful when you wish to reimplement a shell builtin as a shell function, but need to execute the builtin within the function.
$ type echo
echo is a shell builtin
$ function echo(){ builtin echo "'$1'"; }
$ echo hi
'hi'
help builtin
builtin: builtin [shell-builtin [arg ...]] Execute shell builtins.
Execute SHELL-BUILTIN with arguments ARGs without performing command lookup. This is useful when you wish to reimplement a shell builtin as a shell function, but need to execute the builtin within the function. Exit Status: Returns the exit status of SHELL-BUILTIN, or false if SHELL-BUILTIN is not a shell builtin.
From help -m builtin:
NAME
builtin - Execute shell builtins.
SYNOPSIS
builtin [shell-builtin [arg ...]]
DESCRIPTION
Execute shell builtins.
Execute SHELL-BUILTIN with arguments ARGs without performing command
lookup. This is useful when you wish to reimplement a shell builtin
as a shell function, but need to execute the builtin within the function.
Example usage:
cd (){
builtin cd "$@"
pwd
}
This cd's, then prints the new working directory (like in IPython). If you forget the builtin part, it will keep calling itself in an infinite loop.