I have problems saving spaces in a bash script:
CURRENT_YEAR=$(date "+%Y")
MESSAGE=$(eval echo "$(/usr/libexec/PlistBuddy -c "Print NSHumanReadableCopyright" Info.plist)")
/usr/libexec/PlistBuddy -c "Set NSHumanReadableCopyright $MESSAGE" ${CONFIGURATION_BUILD_DIR}/${INFOPLIST_PATH}
Corresponding section of Info.plist:
<NSHumanReadableCopyright>Copyright © BEC, ${CURRENT_YEAR}\nAll rights reserved.</NSHumanReadableCopyright>
The script reads the value from plist, then replaces another variable ( CURRENT_YEAR) with the value that was read from plist.
The problem is that the new line in MESSAGE is causing problems. If I use \n, instead of a new line, "n" is displayed. If the actual new line character is used, the command fails because "Everything" is interpreted as a new command.
How to get out of a new line? Is there a better way to do this? I have very little bash -foo.
Update - Solution:
Thanks for the help. The solution was to go crazy with quotes. Here's the end result:
CURRENT_YEAR="$(date "+%Y")"
MESSAGE_TEMPLATE="$(/usr/libexec/PlistBuddy -c "Print NSHumanReadableCopyright" Info.plist)"
MESSAGE=$(eval echo '"'"$MESSAGE_TEMPLATE"'"')
/usr/libexec/PlistBuddy -c "Set NSHumanReadableCopyright $MESSAGE" ${CONFIGURATION_BUILD_DIR}/${INFOPLIST_PATH}