Posted on 12-05-2018 08:36 AM
I am working on a script that will check if an application is present and then run some commands. I am trying to write this so that I can easily change it later for a different application so I am putting the application and the path in a variable. The problem I have run into is that there are spaces in the path and so I am having trouble getting the IF statement to work and other commands. I think it is just where and when to put quotes and the character. If I take out the variable and place the path directly everything is fine.
Below is the main part I am trying to get working. If I can get that to work then I am sure I can get the rest of it.
#!/bin/bash Apple_Installer="/Applications/Install macOS Mojave.app" if [ -d "$Apple_Installer" ]; then Installer_Version=$(/usr/libexec/PlistBuddy -c 'Print CFBundleShortVersionString' "$Apple_Installer"/Contents/Info.plist) else echo "Not Present" fi exit 0
Solved! Go to Solution.
Posted on 12-05-2018 08:39 AM
You don't need any 's in your path if you are double quoting the path. Quoting handles the spaces without needing to escape them that way.
So change this line
Apple_Installer="/Applications/Install macOS Mojave.app"
to
Apple_Installer="/Applications/Install macOS Mojave.app"
and it should work fine.
*Edited to remove the second backslash
Posted on 12-05-2018 08:39 AM
You don't need any 's in your path if you are double quoting the path. Quoting handles the spaces without needing to escape them that way.
So change this line
Apple_Installer="/Applications/Install macOS Mojave.app"
to
Apple_Installer="/Applications/Install macOS Mojave.app"
and it should work fine.
*Edited to remove the second backslash
Posted on 12-06-2018 08:25 AM
Ya, yes. That worked, thank you.
I had tried that previously but was still having an issue with a different command but later discovered that I had missed the quotes in that command.
Thank you.