问题描述
我正在尝试在非交互式 bash shell 中使用别名.我已经在 ~/.bashrc
中定义了我的别名,并且我已经设置了变量 BASH_ENV=~/startUpFile
.startUpFile 的内容是source ~/.bashrc
.
I am trying to use aliases in a non-interactive bash shell. I have defined my aliases in ~/.bashrc
and I have set the variable BASH_ENV=~/startUpFile
. The contents of the startUpFile are source ~/.bashrc
.
当我执行 alias
命令时,我可以看到我的别名被识别.但是,如果我尝试使用 ~/.bashrc
中定义的别名,Bash 无法识别它.它给了我未知的命令错误.
I can see that my aliases are recognized, when I execute the alias
command. However, if I try to use an alias defined in ~/.bashrc
, Bash can't recognized it. It gives me the unknown command error.
使用 TCSH shell 很容易做到这一点,因为 ~/.cshrc
文件总是被读取.
With the TCSH shell it is pretty easy to do this because the ~/.cshrc
file is always read.
有什么想法可以用 Bash shell 做到这一点吗?
Any ideas how I can do this with a Bash shell?
推荐答案
shopt -s expand_aliases
命令将允许在非交互式 shell 中扩展别名.
The command shopt -s expand_aliases
will allow alias expansion in non-interactive shells.
这篇关于为什么非交互式 Bash shell 中的别名不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!