bash:意外标记“elif”附近的语法错误

bash:意外标记“elif”附近的语法错误

shell脚本片段如下

if [[ $OS == Linux ]] ; then

    LINUX_FC=gfortran
#
#   set 32 or 64 Bits executable
#
    ARCH=`uname -m`
    echo "PROCESSOR IS: $ARCH"
    if [ [ $ARCH == x86_64 ] ]  ; then
        BITS=SIXTYFOUR;
    else
        BITS=THIRTYTWO;
    fi

elif [[ $OS == Darwin ]] ; then

        DARWIN_FC=gfortran;

else
    BITS=THIRTYTWO;
fi;

错误是

OPERATING SYSTEM IS: Linux
: command not found
jobcomp1: line 34: syntax error near unexpected token `elif'
'obcomp1: line 34: `elif [ [ $OS == Darwin ] ] ; then

答案1

shell 确实不喜欢括号之间的空格:

if [ [ $ARCH == x86_64 ] ]  ; then

它期望类似的东西

if [[ $ARCH == x86_64 ]]  ; then

或更好)

if [ $ARCH = x86_64 ]  ; then

(制作特定于 bash 的脚本是没有意义的,因此也==变得=如此)。

相关内容