Using echo to print double quotes along with variable substitution


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Using echo to print double quotes along with variable substitution
# 1  
Old 01-28-2010
Question 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
Code:
echo "<a href="$var">$var</a>" > file.html

But with this " in href is not coming in file. Can any one please suggest me a way to do it. Is it possible to use anything else rather than " in echo command that can be used for variable interpolation also.


Thanks in advance.

Last edited by pludi; 01-28-2010 at 04:20 AM..
# 2  
Old 01-28-2010
Hi, is this what you are looking for?
Code:
 echo "<a href="\"$var\"">$var</a>" > file.html

# 3  
Old 01-28-2010
Quote:
Originally Posted by Scrutinizer
Hi, is this what you are looking for?
Code:
 echo "<a href="\"$var\"">$var</a>" > file.html

Thanks for your reply , but still i am not able to do it,

Code is like
Code:
echo "<a href="file:\\\\$var">$var,/a>" > file1.html

So the output should be
<a href="file:\\\\www.abc.com">www.abc.com</a>
can you please suggest me for the above said code.
# 4  
Old 01-28-2010
Try:
Code:
echo "<a href="\"file:\\\\\\\\$var\"">$var</a>" > file.html

-or-
Code:
echo '<a href="file:\\\\'"$var"'">'"$var"'</a>' > file.html

# 5  
Old 01-28-2010
You can also use single quotes in the html string:
Code:
echo "<a href='$var'>$var</a>" > file.html
# or for the other string :
<a href='file:\\\\www.abc.com'>www.abc.com</a>

I Know it's not precisely what you asked for but it's correctly interpreted by the browsers.
What seems me strange is the backslashes. should the syntax not be :
Code:
<a href='file:///www.abc.com'>www.abc.com</a>

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

Printing double quotes in echo command

Please help me to use echo or printf type of command to print some value from variable within double quotes - I want to print the double quote ( " ") also. I tried #!/bin/bash VALUE=some_value echo '{"value" : "$VALUE"}' I was expecting the above script would produce .. {"value" :... (3 Replies)
Discussion started by: atanubanerji
3 Replies

3. 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

4. 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

5. Shell Programming and Scripting

[Solved] echo not updating double quotes in output

Hi , I have a script to update firefox proxy. But the echo is not updating the double quotes. paste /home/names.txt /home/ip.txt | while read i j do mkdir $i echo "user_pref("network.proxy.http", "$j");" >> /home/$i/prefs.js echo "user_pref("network.proxy.http_port", 8080);" >>... (3 Replies)
Discussion started by: ranjancom2000
3 Replies

6. Shell Programming and Scripting

Shell $,/r getting added in echo on variable substitution.

Hi All, I'm trying to run a similar script to copy a files from one location to another. #!/bin/bash source="/home/pradeepk/a.txt" destination="/home/pradeepk/dir1" cp $source $destinationi'm getting following error. cp: cannot stat `/home/pradeepk/a.txt\r': No such file or directorywhen... (1 Reply)
Discussion started by: pradeep2002gs
1 Replies

7. Shell Programming and Scripting

Perl echo with double quotes

I need to echo a string that has double quotes in a Perl script. #!/usr/bin/env perl `echo Rule123 -comment \"blah blah\" >> $filename` I'd like to get below appended to $filename: Rule 123 -comment "blah blah" But instead, the double quotes are lost: Rule 123 -comment blah bah ... (1 Reply)
Discussion started by: slchin
1 Replies

8. Shell Programming and Scripting

print pattern within double quotes

Hi All, I have multiple lines in a file like:- "abc" def "ghi" jkl "mno" 1 I want to print in output:- abc/ghi/mno 1 How can I do this in perl? Regrds, Nilabh -----Post Update----- Additional info:- The last field of the file should be output as it is.In the above example 1 is... (6 Replies)
Discussion started by: nilabh_s
6 Replies

9. Shell Programming and Scripting

Dont want to print double-quotes

Hi, I have a perl script which generates an LDAP report in CSV Format. Issue: Some of attribute values has double-quotes as fed by users. I dont want to print those double-quotes while printing the attribute values. Please let us know how I can overcome this issue. Thank You. ... (2 Replies)
Discussion started by: gazalinawaz
2 Replies

10. Shell Programming and Scripting

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... (4 Replies)
Discussion started by: burton_1080
4 Replies
Login or Register to Ask a Question