shell腳本中使用自定義指令之四---通過加載.bashrc實作
1、.bashrc檔案
alias log_success="figlet Success | lolcat && cowsay -f dragon haha |lolcat"
alias log_fail="figlet Fail | lolcat && cowsay -f sheep Cry |lolcat"
2、子shell執行結果
. /home/xcz/.bashrc
shopt -s expand_aliases
shopt expand_aliases
log_success
==> Fail
log_fail
==> Fail
3、原因(注釋掉這一句可以OK):
.bashrc檔案中
If not running interactively, don't do anything
[ -z "$PS1" ] && return
4、關于$PS1
PS1是互動式SHELL的提示符, 在非互動式的情況下, 該值為空.
a、終端中:
[email protected]$ echo $PS1
==> ${debian_chroot:+($debian_chroot)}\u@\h:\w\$
b、執行 ./test.sh
==> 空行
c、執行 source ./test.sh
==> ${debian_chroot:+($debian_chroot)}\u@\h:\w\$