當需要執行預設shell script時,到底需要寫在哪裡?
讀取順序還要依照是否為“交互式登錄”決定,交互式登錄就是“使用者”使用終端機,而執行一個腳本則屬於“非交互式登錄”
交互式登錄讀取啟動文件順序如下
/etc/profile
~/.bash_profile
~/.bash_login
~/.profile
非交互式登錄讀取啟動文件順序如下
~/.bashrc
這意味著”~/.bashrc”在使用者登錄時,並不會被讀取,如果有需要,可以在“~/.bash_profile”加入以下指令使兩種登錄方式皆會讀取“~/.bashrc”
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
所以,可以在~/.bash_profile寫入以下資訊,來替代常用的整串指令
alias conn='ssh username@192.168.10.2'
即可在終端機輸入conn 取代ssh username@192.168.10.2
alias ll='ls -al'
alias VM='open vnc://username:password@192.168.10.3'
來取代較長的指令,方便使用
參考資料: