PDA

View Full Version : Defaults, and Shell scripts




BollywooD
Sep 21, 2010, 05:25 PM
so I am trying to copy keys from one plist to another, and the following command works well from the command line:
defaults write com.sweetpproductions.SafariCookies `defaults read com.apple.Safari SCautomaticMode`

whereas the following post-install shell script does not?
#!/bin/sh


# remove unneeded defaults
#find all users
for arg in `ls /Users`
do

#copy preferences for all users, if it exists - ignoring the Shared folder
if [ $arg != 'Shared' ]; then
/usr/bin/su $arg -c "/usr/bin/defaults write com.sweetpproductions.SafariCookie `/usr/bin/defaults read com.apple.Safari SCautomaticMode`"

fi
done
exit 0

I get the following error:
22/09/10 7:55:48 AM defaults[895]
Rep argument is not a dictionary
Defaults have not been changed.

can anyone tell me what I am doing wrong?
:confused:
thanks in advance.



chown33
Sep 21, 2010, 06:38 PM
Just a guess...

The man page for bash says this about double-quotes:
Enclosing characters in double quotes preserves the literal value of
all characters within the quotes, with the exception of $, `, and \.
The characters $ and ` retain their special meaning within double
quotes. ...
(Underline added for emphasis.)

So the backtick-delimited command is being evaluated from a different context. You might want to use the -x bash option, like so:
set -x

This will tell bash to echo the command-line before executing it.

BollywooD
Sep 22, 2010, 07:54 PM
You might want to use the -x bash option, like so:
set -x

This will tell bash to echo the command-line before executing it.


I tried, but it didn't work, but you got me on the right path, all I had to do was to escape the single quotations like so:
/usr/bin/su $arg -c "/usr/bin/defaults write com.sweetpproductions.SafariCookie \`/usr/bin/defaults read com.apple.Safari SCautomaticMode\`"


and it works great, thanks for the help.
:D