![]() |
VOOZH | about |
The builtin command in shell scripting is used to execute a shell builtin, passing it arguments, and also retrieving its exit status. Its primary use is to ensure that you can call the original functionality of a builtin command even when a function with the same name is defined.
builtin [shell-builtin [arg ..]]where,
Hereβs a simple example of using the builtin command:
Scenario: You want to create a function named cd, but still want to use the original cd functionality within that function.
Here, we are creating a function to replace the 'cd' command. When you will use cd() function it will change the directory to the desktop directly.
π Linux builtin command ExampleIn this case, every time you use cd, it will move to the Desktop directory, but the functionality of the original cd command is retained by using builtin.
The builtin --help command displays help information for the builtin command.
π builtin --help CommandThis will output detailed help information regarding the builtin command, listing available builtins and their functionality.
The builtin command is particularly useful when you want to override a shell builtin (e.g., cd, echo, test) with a custom function while still being able to access the original builtin behavior. It ensures that the core functionality remains intact within your custom shell functions.