更新时间:2023-12-05 18:54:40
来自 bash
手册页:> p>
From the bash
man page:
当shell非交互式时,别名不会扩展,除非
expand_aliases
shell选项是使用shopt
进行设置(请参阅 SHELL BUILTIN COMMANDS 下的shopt
的
说明
Aliases are not expanded when the shell is not interactive, unless the
expand_aliases
shell option is set usingshopt
(see the description ofshopt
under SHELL BUILTIN COMMANDS below).
所以这应该起作用:
#!/bin/bash
shopt -s expand_aliases
alias I_am_only_ls_alias=ls
I_am_only_ls_alias
脚本通常使用函数,而不使用别名。
Scripts usually use functions, not aliases.