The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Remove double quotes deepakwins UNIX for Dummies Questions & Answers 3 05-30-2008 11:53 AM
Double quotes or single quotes when using ssh? password636 Shell Programming and Scripting 3 05-29-2008 08:52 PM
Displaying double quotes using Perl kbdesouza Shell Programming and Scripting 2 12-10-2007 11:18 AM
put double quotes for a column sumeet Shell Programming and Scripting 3 05-09-2007 07:20 PM
How do I insert double quotes dsean Shell Programming and Scripting 3 05-26-2006 01:28 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 12-01-2005
burton_1080 burton_1080 is offline
Registered User
  
 

Join Date: Dec 2005
Posts: 3
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 (permalink)  
Old 12-01-2005
Perderabo's Avatar
Perderabo Perderabo is offline Forum Staff  
Unix Daemon
  
 

Join Date: Aug 2001
Location: Ashburn, Virginia
Posts: 9,111
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 (permalink)  
Old 12-01-2005
burton_1080 burton_1080 is offline
Registered User
  
 

Join Date: Dec 2005
Posts: 3
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 (permalink)  
Old 12-01-2005
grasper grasper is offline
Registered User
  
 

Join Date: Sep 2005
Posts: 45
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 (permalink)  
Old 12-01-2005
burton_1080 burton_1080 is offline
Registered User
  
 

Join Date: Dec 2005
Posts: 3
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
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 10:04 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0