Why aliases in a non-interactive Bash shell do not work

前端 未结 4 785
青春惊慌失措
青春惊慌失措 2020-11-27 15:27

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

4条回答
  •  隐瞒了意图╮
    2020-11-27 16:08

    .bashrc is only processed by interactive shells.

    In addition, aliases are not expanded when the shell is not interactive, unless the expand_aliases shell option is set using shopt. Unless, of course, POSIX mode is invoked by calling the shell with the name sh instead of bash.

    People who use aliases a lot often source their .bashrc at the end of their profile so that the aliases are there even for non-interactive shells. This might not be the best way, but it is pretty common.

    It's things like this that lead me to believe that in the 21st century we should abandon shell scripts in favor of a full-blown language like Python. It's a lot more predictable.

提交回复
热议问题