ステップ2 if-elseチェックで予期しないトークン 'elif'の近くに構文エラーが発生しました。

ステップ2 if-elseチェックで予期しないトークン 'elif'の近くに構文エラーが発生しました。

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

おすすめ記事