Why aliases in a non-interactive Bash shell do not work
.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.
The command shopt -s expand_aliases
will allow alias expansion in non-interactive shells.