shell script used alias function

nux shell has interactive and non-interactive modes of operation. Enter the command shell we use every day to get results is in an interactive way, while non-interactive mode shell script.

alias shell provides functionality to simplify our daily operations, so that we can take a simple name for a complex command, thus improving our efficiency. In interactive mode, alias extensions shell is open, so we can type your own alias alias defined to execute the corresponding command.

However, in non-interactive mode, alias expansion is disabled by default, in which case you can still define alias alias, but the alias alias shell does not extend to the corresponding command, but the alias alias itself as the command is executed, if the shell built-in commands and the PATH command aliases are not the same name and alias, the shell will "complain" can not find the specified command.

Well, there is no way to enable alias expansion in the non-interactive mode it? The answer is to use the built-in command shell command to open the alias shopt expansion options. shopt is a shell built-in commands, you can control opening and closing of the shell options to control the behavior of the shell. shopt use is as follows:

shopt -s opt_name                 Enable (set) opt_name.
shopt -u opt_name                 Disable (unset) opt_name.
shopt opt_name                    Show current status of opt_name.

Such as the following examples:

 

 At this cat and ls you can use the alias function.

Guess you like

Origin www.cnblogs.com/FengGeBlog/p/12165364.html