bash alias in scripts

bash在非交互式模式下是不扩展alias定义的,除非明确指定shell选项expand_aliases

因此要在脚本中使用alias定义,可以这样:

1
2
3
shopt -s expand_aliases
source ~/.bash_aliases
alias ll='ls -lht'

References:
[1]How to make alias command work in bash script or bashrc file
[2]Why doesn’t my Bash script recognize aliases?