Defaults, and Shell scripts

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

  1. macrumors 6502

    Joined:
    Apr 27, 2005
    Location:
    Surfers Paradise
    #1
    so I am trying to copy keys from one plist to another, and the following command works well from the command line:
    Code:
    defaults write com.sweetpproductions.SafariCookies `defaults read com.apple.Safari SCautomaticMode`
    whereas the following post-install shell script does not?
    Code:
    #!/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:
    Code:
    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.
     
  2. macrumors 603

    Joined:
    Aug 9, 2009
    #2
    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:
    Code:
    set -x
    
    This will tell bash to echo the command-line before executing it.
     
  3. thread starter macrumors 6502

    Joined:
    Apr 27, 2005
    Location:
    Surfers Paradise
    #3

    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:
    Code:
    /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
     

Share This Page