Ampersand in a shell script

I’m trying to script a shell script for a remote location that will add the current user to the _lpadmin group on Mountain Lion. The problem (other than I don’t really know what I’m doing) is that the admin password has an ampersand in it.

tell application "System Events" to set userName to name of current user
-- display dialog userName

set textEntered to display dialog "Enter your admin password:" default answer "" with hidden answer
set adminPW to the text returned of textEntered as string

set sScript to "dseditgroup -o edit -u adminuser -P " & adminPW & " -a " & userName & " -t user _lpadmin" as string


--display dialog sScript as string

do shell script sScript

When i display the script it appears correct, password with an ampersand in it and all. But when I do the script, it errors out, treating the ampersand in the password as a concatenation symbol and therefore throwing the shell script off. I’ve tried it setting adminPW without specifying as string, as well.

How can I get around this (besides changing the password, which is not an option)?

Thanks.

Don

The answer will be ‘quoted form’ It’s escaping an string. When sending (sub)strings from AppleScript to bash you should always use quoted form when the strings are dynamic.

set sScript to "dseditgroup -o edit -u adminuser -P " & quoted form of adminPW & " -a " & quoted form of userName & " -t user _lpadmin" as string

Thanks, that works. I had used quoted form on one of the variables in the script, but not the other when I was trying stuff, so that gets it to work just right.

Thanks again

Don