同じリストを使用して複数のループコマンドを持つスクリプトがあります。Bashループのコマンドに空白を含むリスト
# List of applications
read -r -d '' Applications << EndOfList
/Applications/App.app
/Applications/App2.app
/Applications/App3.app
/Applications/Another App.app
EndOfList
for file in $Applications
do
if [ -e "$file" ]; then
echo ""$file" found"
fi;
done
exit 1
これは、アプリケーション名にスペースがあるため、リストの4番目のアプリケーションを除いて正常に動作しているようです。私はデバッグモードでスクリプトを実行すると、これが出力されます。
+ read -r -d '' Applications
+ for file in '$Applications'
+ '[' -e /Applications/App.app ']'
+ for file in '$Applications'
+ '[' -e /Applications/App2.app ']'
+ for file in '$Applications'
+ '[' -e /Applications/App3.app ']'
+ for file in '$Applications'
+ '[' -e /Applications/Another ']'
+ for file in '$Applications'
+ '[' -e App.app ']'
+ exit 1
私はそれと複数の他の方法を引用し、バックスラッシュでエスケープしようとしましたが、私はそれを動作させることができませんでした。
はい!それは確かに行く方法です。ありがとう!私はこの権利[ここ](http://mindspill.net/computing/linux-notes/using-the-bash-ifs-variable-to-make-for-loops-split-with-html-html-html-html-html-html-html-html-html-html-html-html)に関するいくつかの詳細を見つけました。非空白文字/) – Matter