In a shell script I'm reading strings from the Info.plist in application bundles, in this example from the Copyright key, whereas $FILEPATH is the path to an application bundle, e.g. /Applications/TextEdit.app
#!/bin/bash
PLIST=$(/usr/bin/defaults read "$FILEPATH/Contents/Info.plist")
COPYRIGHT=$(echo "$PLIST" | /usr/bin/awk -F" = " '/NSHumanReadableCopyright/{print $2}' RS=';' | /usr/bin/sed 's/^"\(.*\)"$/\1/')
echo "Copyright: $COPYRIGHT"
Note: I'm not reading the key directly, which would be easier, of course; it's read into the variable PLIST, so the script can read other keys as well later on, and doesn't have to use the defaults command over and over.
Now the output is (for example) Copyright: Copyright \\U00a9 1995-2015, Apple Inc.\\nAll rights reserved.
Obviously the copyright sign \U00a9 was escaped, as was the line break, but how can I solve this problem so that the shell script actually prints out the string as it was meant to, i.e. with copyright sign and line break?
PS: at the end I would probably remove the line break, but as the first step I'd want to echo the whole thing as intended.
I would to use
plutilinstead of thedefaults. The:will print
the
-pmean human readable format - so hard to process. Therefore, is better convert theplisttojson, for example:the
-rmean convert to human-readableJSON, e.g.Now you can easily filter out the
NSHumanReadableCopyrightkey, even usingawk, but it is much better to use some real tool.Mac by default has installed
perland also theJSON::PPmodule. So the:will output
Edit: tested the whole as one long line from the comment:
and prints OK...