Double Quotes within a variable


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Double Quotes within a variable
# 1  
Old 12-01-2005
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
# 2  
Old 12-01-2005
Huh?
Code:
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.
# 3  
Old 12-01-2005
It echos fine but does not run fine.

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.
# 4  
Old 12-01-2005
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?
# 5  
Old 12-01-2005
Not sure

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
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Spaces in double quotes in variable ?

Hi got this issue and was wondering if someone could please help out ? var='." "' echo $var ." " I 'll get ." " and not ." with 10 spaces in between " Thanks (3 Replies)
Discussion started by: stinkefisch
3 Replies

2. Shell Programming and Scripting

Replace Double quotes within double quotes in a column with space while loading a CSV file

Hi All, I'm unable to load the data using sql loader where there are double quotes within the double quotes As these are optionally enclosed by double quotes. Sample Data : "221100",138.00,"D","0019/1477","44012075","49938","49938/15043000","Television - 22" Refurbished - Airwave","Supply... (6 Replies)
Discussion started by: mlavanya
6 Replies

3. Shell Programming and Scripting

How to pass two words within double quotes as variable?

Hi All, OS - Suse 10 ksh --version version sh (AT&T Research) 93s+ 2008-01-31 I am passing two words within double quotes ("Application Developer") to script as variable, but script is adding two single quotes between two words like ("Application' 'Developer"). below is simple test... (4 Replies)
Discussion started by: srimitta
4 Replies

4. Shell Programming and Scripting

Issue with Single Quotes and Double Quotes for prompt PS1

Hi, Trying to change the prompt. I have the following code. export PS1=' <${USER}@`hostname -s`>$ ' The hostname is not displayed <abc@`hostname -s`>$ uname -a AIX xyz 1 6 00F736154C00 <adcwl4h@`hostname -s`>$ If I use double quotes, then the hostname is printed properly but... (3 Replies)
Discussion started by: bobbygsk
3 Replies

5. Shell Programming and Scripting

Double quotes and variable proble in echo

HI Guys, I want to echo below line in my file :- lpd | grep AL | nawk '{print "1dLA - " $0} How can i echo same Output (4 Replies)
Discussion started by: pareshkp
4 Replies

6. UNIX for Dummies Questions & Answers

awk for inserting a variable containing single and double quotes

Hi i have to insert the below line into a specific line number of another file export MBR_CNT_PRCP_TYPE_CODES_DEL="'01','02','04','05','49','55','UNK'" I have passed the above line to a variable say ins_line. I have used below command to perform the insert awk 'NR==3{print "'"${ins_line}"'"}1'... (1 Reply)
Discussion started by: sathishteradata
1 Replies

7. UNIX for Dummies Questions & Answers

grep single quotes or double quotes

Unix superusers, I am new to unix but would like to learn more about grep. I am very familiar with regular expressions as i have used them for searching text files in windows based text editors. Since I am not very familiar with Unix, I dont understand when one should use GREP with the... (2 Replies)
Discussion started by: george_vandelet
2 Replies

8. Shell Programming and Scripting

Using echo to print double quotes along with variable substitution

Hi, I am generating html code using cshell, but i am having one problem while printing double quotes, I need to write following code in file. where $var contains list of web address <a href="$var">$var</a> So i am using echo "<a href="$var">$var</a>" > file.html But with this " in... (4 Replies)
Discussion started by: sarbjit
4 Replies

9. Shell Programming and Scripting

Single quotes and double quotes

Hi guys, I have a sed line in double quotes which works fine, but I want it to be in single quotes here is the sed line sed "/abc_def/s/\'.*\'/\'\${abc_def}\'/" can some one give the equivalent to the above script in single quotes Thanks a ton (5 Replies)
Discussion started by: sol_nov
5 Replies

10. Shell Programming and Scripting

Double quotes or single quotes when using ssh?

I'm not very familiar with the ssh command. When I tried to set a variable and then echo its value on a remote machine via ssh, I found a problem. For example, $ ITSME=itsme $ ssh xxx.xxxx.xxx.xxx "ITSME=itsyou; echo $ITSME" itsme $ ssh xxx.xxxx.xxx.xxx 'ITSME=itsyou; echo $ITSME' itsyou $... (3 Replies)
Discussion started by: password636
3 Replies
Login or Register to Ask a Question