TrumanWong

enable

Enable or disable shell builtins

Summary

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

The main purpose

  • Disable one or more built-in commands.

  • Enable one or more built-in commands.

  • Directly call an external command with the same name as the disabled built-in command and found in $PATH.

  • Print all built-in commands, whether disabled or not.

  • Prints enabled built-in commands.

  • Print built-in commands that are disabled.

  • Print the enabled posix standard built-in commands.

  • Print the disabled POSIX standard built-in commands.

  • Print POSIX standard built-in commands, whether disabled or not.

  • Load built-in commands from dynamic libraries.

  • Removed built-in commands loaded from dynamic libraries.

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.

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

  2. This command is a built-in bash command. For related help information, please see the help command.