Defaults, and Shell scripts

Discussion in 'Mac Programming' started by BollywooD, Sep 21, 2010.

  1. BollywooD
    Expand Collapse
    macrumors 6502

    Apr 27, 2005
    Surfers Paradise
    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 SCautomaticMode`
    whereas the following post-install shell script does not?
    # remove unneeded defaults
    #find all users
    for arg in `ls /Users`
    #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 SCautomaticMode`"
    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?
    thanks in advance.
  2. chown33
    Expand Collapse
    macrumors 604

    Aug 9, 2009
    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.
  3. BollywooD
    Expand Collapse
    thread starter macrumors 6502

    Apr 27, 2005
    Surfers Paradise

    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 SCautomaticMode\`"
    and it works great, thanks for the help.

Share This Page