I have a script with multiple loop commands using the same list. It looks like this:
# 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
This seems to work fine except for the fourth application in the list, because there's a space in the application name. If I run the script in debug mode, this is the output:
+ 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
I've tried escaping with a backslash, quoting it and multiple other ways but I could not get it to work.