当我通过 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