Double Quotes within a variable

This is a totally dumb newbie question, but I have not been able to find t he answer in the BASH book or online.

I am trying pass a double quoted variable to the command line.

variable = "-b \"dc=example,dc=com\""

When I run sh -x the variable comes out as '-b "dc=example,dc=com"' is should be: -b "dc=example,dc=com"
the single quotes around the double quotes is is breaking the command.
I have tried
${variable}
\"${variable}\"
$variable
"$variable"
\"$variable\"

None of come up with the desired quote.

Any input is appreciated!

-Rob

Huh?

bash-2.05b$ variable="-b \"dc=example,dc=com\""
bash-2.05b$ echo $variable
-b "dc=example,dc=com"
bash-2.05b$

*shrug* I don't see any single quotes popping into existence. The value of variable was passed to echo command line exactly like you say you wanted.

You have to run it in a script.

#---------
#!/bin/bash
variable="-b \"dc=example,dc=com\""
ldapsearch $variable
echo This is echoed: $variable
#----------

when you run sh -x to it this is the result.
+ variable=-b "dc=example,dc=com"
+ ldapsearch -b '"dc=example,dc=com"'
ldap_sasl_interactive_bind_s: Can't contact LDAP server
+ echo This is echoed: -b '"dc=example,dc=com"'
This is echoed: -b "dc=example,dc=com"

You will notice that is echos fine but when it is run it has the single quotes.
Ignore the ldap error this is just an example of how BASH add single quote when the command is run.

I may have misunderstood your problem and I've gone a bit 'quote-blind' looking at your output, but it seems to me the single quotes are there because you're running the script in debug mode and the shell is using them to explain what is being echoed. Or have I missed the point?

I think you might be right. Below are the results from the actual script. The thing that screws me up is i CAN copy the echoed command into the command prompt and it works. I am at a loss. The single quote in the debug lines make no sense though.

#variables
base="-b \"dc=junk,dc=example,dc=stuff\"" # Replace with your domain name
user="-D \"cn=ESX Ldap Account,OU=Linux,dc=junk,dc=example,dc=stuff\""

# Running Echo Command
+ echo ldapsearch -x -LLL -H ldap://junk.example.stuff -b '"dc=junk,dc=example,dc=stuff"' -D '"cn=ESX' Ldap 'Account,OU=Linux,dc=junk,dc=example,dc=stuff"' -w password -u -tt -T /usr/LDAP/Member '"CN=Jon' H. 'Doe"' samAccountName

# Result from Echo
ldapsearch -x -LLL -H ldap://junk.example.stuff -b "dc=junk,dc=example,dc=stuff" -D "cn=ESX Ldap Account,OU=Linux,dc=junk,dc=example,dc=stuff" -w password -u -tt -T /usr/LDAP/Member "CN=Jon H. Doe" samAccountName

# Runing Ldapsearch comman
+ ldapsearch -x -LLL -H ldap://junk/example.stuff -b '"dc=junk,dc=example,dc=stuff"' -D '"cn=ESX' Ldap 'Account,OU=Linux,dc=junk,dc=example,dc=stuff"' -w password -u -tt -T /usr/LDAP/Member '"CN=Jon' H. 'Doe"' samAccountName