9
構文はどのようにbashで動作しますか?これはelse文のCスタイルの疑似コードです。例:bashで/ then/elseifがネストされるとどうなりますか?
構文はどのようにbashで動作しますか?これはelse文のCスタイルの疑似コードです。例:bashで/ then/elseifがネストされるとどうなりますか?
多くの文法に含まれている曖昧さについては、あなたの疑問に思っています。 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
パーフェクト!ありがとうございました –