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

관련 정보