Enable or disable shell builtins
enable [-a] [-dnps] [-f filename] [name ...]
-a Print all builtin commands, whether disabled or not.
-d removes built-in commands loaded from dynamic libraries.
-n Disables built-in commands or displays disabled built-in commands.
-p Print in reusable format.
-s displays only posix standard built-in commands in the startup state.
-f loads built-in commands into the dynamic library.
-ns prints disabled POSIX standard built-in commands.
-as Print POSIX standard built-in commands, whether disabled or not.
filename: dynamic library file name.
name (optional): built-in command, can be multiple.
enable returns success unless name is not a built-in command or an error occurs.
# posix special builtin
# Assuming no built-in commands are disabled
# Disable two posix standard built-in commands
enable -n set source
# Print the disabled posix standard built-in commands
enable -ns
# Print POSIX standard built-in commands, whether disabled or not.
enable -as
# Print the enabled posix standard built-in commands
enable -s
# Assuming no built-in commands are disabled
# Disable one or more built-in commands
enable -n echo pwd
# Print all built-in commands, whether disabled or not.
enable -a
# Print enabled built-in commands
enable
# Print disabled built-in commands
enable -n
# Enable one or more built-in commands
enablepwd
Q: What about the demonstration of -f, -d and -p?
A: To explain, -f and -d are limited to personal abilities and no suitable examples have been found. If you have better examples, please provide PR;
After I verified that there seems to be no difference whether the -p option is used, you can compare the difference between enable -p|cat -A and enable|cat -A. (Note: cat -A is used to display invisible characters)
Q: Is it possible to disable enable itself? Can I still disable or enable built-in commands later?
A: Yes; no.
When a linux shell command is executed, the shell always first searches for the command in its own shell builtin. If it is found, it executes the command; if it cannot find the command, it will follow the path specified by the environment variable $PATH. Find the command to be executed. It looks like there is no way to write user's own commands to replace the shell builtin commands. Fortunately, with the enable command we can do just that.
For knowledge about the priority of the command call with the same name, please refer to the tips part of the builtin command first, and then continue reading the following part;
When the built-in command echo is not disabled, if you want to call the external command echo, you can only write /usr/bin/echo like this;
When we disable echo, the priority order becomes this:
Functions > External Commands
If the environment in which the command is executed does not have an echo function, then the echo called is an external command.
This command is a built-in bash command. For related help information, please see the help command.
优先推荐相关内容,同时保留你的阅读轨迹和收藏入口。