2013-03-10 7 views

答えて

25

多くの文法に含まれている曖昧さについては、あなたの疑問に思っています。 bashでそのようなことはありません。 ifはすべて、ifブロックの終わりを示すfiというコンパニオンによって区切られなければなりません。

他の構文上のエラー以外にも、あなたの例は有効なbashスクリプトではないことがわかります。このようなエラーを修正しようとしています

if condition 
    then 
    echo "do this stuff" 

elif condition 
    then 
    echo "do this stuff" 

elif condition 
    then 
    echo "do this stuff" 
    if condition 
     then 
     echo "this is nested inside" 
# this else _without_ any ambiguity binds to the if directly above as there was 
# no fi colosing the inner block 
    else 
     echo "this is nested inside" 

# else 
#  echo "not nested" 
# as given in your example is syntactically not correct ! 
# We have to close the last if block first as there's only one else allowed in any block. 
    fi 
# now we can add your else .. 
    else 
     echo "not nested" 
# ... which should be followed by another fi 
fi 
+0

パーフェクト!ありがとうございました –

関連する問題