bashの[テスト]と[[テスト]]の違いは何ですか? 一方が他方よりも適切なのはいつ;で、最後に何をしますか?
if [[ -z $DIRECTORY ]];
then
DIRECTORY=html
fi
if [ ! -d "$DIRECTORY" ]; then
echo installation directory "'${DIRECTORY}'" does not exist
exit 1
fi
bashの[テスト]と[[テスト]]の違いは何ですか? 一方が他方よりも適切なのはいつ;で、最後に何をしますか?
if [[ -z $DIRECTORY ]];
then
DIRECTORY=html
fi
if [ ! -d "$DIRECTORY" ]; then
echo installation directory "'${DIRECTORY}'" does not exist
exit 1
fi
[[[コマンドに似た (しかしより強力な) bash キーワードです。http://mywiki.wooledge.org/BashFAQ/031およびhttp://mywiki.wooledge.org/BashGuide/TestsAndConditionalsを参照してください。POSIX sh 用に作成している場合を除き、[[.
通常、次の場合に単一の角括弧を使用します。
if [ -L $file ]; thenif [ $a -lt $b ]; then" "文字列で何かをチェックし、特殊文字を通常どおりに使用および処理したい(例: アスタリスク):if [ -z "$string" ]; then通常、次の場合は角括弧を二重にします。
if [[ "$string1" == *[sS]tring* ]]; thenif [[ -a *.sh ]]; thenif [[ $a == 3 || $b == 4]]; then" "[はシェル用、[[は bash 用です。
例:
Try [ $A -eq 1 ]:$Aが設定されていない場合、エラーが発生します。
[[ $A -eq 1 ]]動作します。