當我透過 SSH 連接到我的盒子時,不斷收到此錯誤。
-bash: /root/.bashrc: line 65: syntax error near unexpected token `elif'
-bash: /root/.bashrc: line 65: `elif [ -n "$BASH_VERSION" ]; then'
這就是我在這些方面的內容
if [ -n "$ZSH_VERSION" ]; then
# assume Zsh
elif [ -n "$BASH_VERSION" ]; then
PS1="⚡️$yellow $dircolor \W $lightpurple $white"
if [ $USER == 'root' ]
then
export PS1="$white┌──[$red\u$white@$red\h$white]──$white[$red\w$white] \n└── $white"
else
export PS1="$white┌──[$lightgreen\u$white@$lightgreen\h$white]──$white[$lightgreen\w$white] \n└── $white"
fi
else
# assume something else
fi
我只檢查是否 zsh/bash 並相應地設定我的 PS1。
我的文法有問題嗎?
答案1
那是因為你的if
身體是空的。嘗試新增一個虛擬指令,例如:
,或最好重寫您的程式碼而不測試 zsh:
if [ -n "$BASH_VERSION" ]; then
PS1="⚡️$yellow $dircolor \W $lightpurple $white"
if [ $USER == 'root' ]
then
export PS1="$white┌──[$red\u$white@$red\h$white]──$white[$red\w$white] \n└── $white"
else
export PS1="$white┌──[$lightgreen\u$white@$lightgreen\h$white]──$white[$lightgreen\w$white] \n└── $white"
fi
fi