enable

Enable or disable shell builtins

Summary

enable [-a] [-dnps] [-f filename] [name ...]

The main purpose

Options

-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.

Parameters

filename: dynamic library file name.

name (optional): built-in command, can be multiple.

return value

enable returns success unless name is not a built-in command or an error occurs.

Example (the following content will not list the return value due to space limitations)

# 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&A

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.

Notice

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.