Enable or disable shell built-in commands.
enable [-a] [-dnps] [-f filename] [name ...]
$PATH.-a Print all built-in commands, whether disabled or not.
-d Remove built-in commands loaded from a dynamic library.
-n Disable built-in commands or show disabled built-in commands.
-p Print built-in commands in a reusable format.
-s Display only enabled POSIX special built-in commands.
-f Load built-in commands from a dynamic library.
-ns Print disabled POSIX special built-in commands.
-as Print all POSIX special built-in commands, whether disabled or not.
filename: The dynamic library filename.
name (optional): Built-in command(s). Multiple names can be specified.
enable returns success unless name is not a built-in command or an error occurs.
# POSIX special built-ins
# Assuming no built-ins are disabled
# Disable two POSIX special built-ins
enable -n set source
# Print disabled POSIX special built-ins
enable -ns
# Print all POSIX special built-ins
enable -as
# Print enabled POSIX special built-ins
enable -s
# Assuming no built-ins are disabled
# Disable one or more built-in commands
enable -n echo pwd
# Print all built-in commands
enable -a
# Print enabled built-in commands
enable
# Print disabled built-in commands
enable -n
# Enable one or more built-in commands
enable pwd
Q: Where are the demonstrations for -f, -d, and -p?
A: Regarding -f and -d, suitable examples haven't been found yet. If you have better examples, feel free to submit a pull request.
For the -p option, there seems to be no visible difference in output; you can compare enable -p | cat -A and enable | cat -A to check for invisible characters.
Q: Can I disable enable itself? Can I still enable/disable built-ins after that?
A: Yes, you can disable it. However, once disabled, you cannot use it to enable or disable any built-in commands until it is re-enabled (which usually requires a new shell session).
When a Linux shell command is executed, the shell always looks for the command in its built-ins first. If found, it executes it. If not, it searches through the paths specified in the
$PATHenvironment variable. It might seem like there's no way to override a shell built-in with a user-defined command. Fortunately, theenablecommand allows us to do exactly that.
builtin command.When the built-in echo is not disabled, to call the external echo command, you must use the full path like /usr/bin/echo.
When echo is disabled, the priority becomes:
Function > External Command
If no echo function exists, the external command will be called.
help command.