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\"
#---------
#!/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\""