bashaliasnon-interactiveshopt

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


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.

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.

With the TCSH shell it is pretty easy to do this because the ~/.cshrc file is always read.

Any ideas how I can do this with a Bash shell?


Solution

  • The command shopt -s expand_aliases will allow alias expansion in non-interactive shells.