I'm having trouble preserving whitespace 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}
The relevant section Info.plist:
<NSHumanReadableCopyright>Copyright © BEC, ${CURRENT_YEAR}\nAll rights reserved.</NSHumanReadableCopyright>
The script reads a value from a plist, then substitutes another variable (CURRENT_YEAR
) into the the value that was read from the plist.
The problem is that the new line in MESSAGE is causing problems. If I use \n
then an 'n' is displayed instead of a new line. If an actual new line character is used then the command fails because 'All' is interpreted as a new command.
How do I escape the 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 finished 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}