1
這個問題是我的問題的分支whether there's anything wrong with having aliases on a production server。在不使用bashrc或bash_profile或bash_aliases的終端會話中激活別名?
所以我試着用一些別名
#!/bin/sh
echo "creating aliases..."
alias f='clear;cd ..;ls;pwd'
alias ff='clear;cd ../..;ls;pwd'
沒過chmod +x al.sh
創建一個shell腳本,並運行腳本./al.sh
,但是雖然「創建別名...」得到了印結,沒有一個別名工作,因爲只有在腳本運行之前它們才顯然活躍。
那麼有沒有一種方法可以運行包含我想要的別名的腳本,只要終端會話處於活動狀態,這些別名就會保持活動狀態?基本思想是,不要爲使用相同服務器的同事造成問題。
登錄時如何採購文件? – fedorqui
'#!/ bin/sh'可能與'bash'不一樣......所以,如fedorqui建議的那樣,使用'source al.sh'或'。 al.sh',但刪除「source」忽略的shebang行。 – Sundeep
shebang創建一個新的子shell,並在該子shell中設置別名。腳本結束時,子shell結束。而正確定義的別名已經消失了。您不能從子外殼內修改父外殼。 – ceving