Printing double quotes in echo command


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Printing double quotes in echo command
# 1  
Old 09-03-2017
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
HTML Code:
#!/bin/bash
VALUE=some_value
echo '{"value" : "$VALUE"}'
I was expecting the above script would produce ..
HTML Code:
{"value" : "some_value"}
But I am not getting the desired result. Rather the above script is producing
HTML Code:
{"value" : "$VALUE"}
Thank you very much
# 2  
Old 09-03-2017
The single quotes are preventing variable expansion. Try:
Code:
#!/bin/bash
VALUE=some_value
echo "{\"value\" : \"$VALUE\"}"

or
Code:
#!/bin/bash
VALUE=some_value
printf '{"value" : "%s"}\n' "$VALUE"

# 3  
Old 09-03-2017
Got the answer from other threads..

HTML Code:
echo "{\"javapath\" : \"$JAVAPATH\"}"
Smilie
Thanks
# 4  
Old 09-03-2017
Or
Code:
echo '{"value" : "'"$VALUE"'"}'

a concatanation of 'string' "string" 'string'.
$VALUE is evaluated (but not otherwise expanded) because it's inside "string".
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

sed command to replace consecutive double quotes

I need to replace consecutive double quotes in a csv file, the data in the file is enclosed in double quotes but there are some places where the quotes are repeating Example is below Incoming data is : "Pacific Region"|"PNG"|"Jimmy""|""| Need output as: "Pacific... (10 Replies)
Discussion started by: abhilashnair
10 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

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

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

5. Shell Programming and Scripting

How to pass a parameter with double quotes around it to a command

In a bash script, I need to pass a parameter that has space in-between using double quotes as follows: CMD="SomeExecutable" # Parameter that has a space in-between PARAM1="TIMO 2" CMD_IN="--name=\"$PARAM1\"" CMD_OUT=`$CMD $CMD_IN` expected/required command execution:... (4 Replies)
Discussion started by: Timo
4 Replies

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

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

How to alias an awk command with single and double quotes?

Hi, I am trying to write the following command as an alias in my .bashrc file. bjobs -u all | awk '{if (NR > 1) {username++;}}END{{print"\nJOBS BY USER:\n"} for (i in username) {print username,i;}{print"\n Total Jobs=",NR-1,"\n" }}' The command simply puts how many jobs each user is... (2 Replies)
Discussion started by: jacekmaciek
2 Replies

9. Shell Programming and Scripting

ksh execute command containing double quotes

How do I execute a command containing a double quote ? I pass a variable to grep that contains spaces, so I need to quote it, but it does not work. #!/usr/bin/ksh set -x txt='"next to"' cmd="grep $txt ~dpearso5/file2" echo $cmd $cmd This is the error I get: + grep "next to"... (1 Reply)
Discussion started by: pearson05
1 Replies

10. Shell Programming and Scripting

unix command to insert double quotes

Hi, I am looking for a unix command which inserts double quotes around all values in a text file. For example, Input: 1234 200 4686 3506056 9646 457 5647 5066762 5656 366 5869 5978459 Output: "1234" "200" "4686" "3506056" "9646" "457" "5647" "5066762" "5656" "366" "5869"... (2 Replies)
Discussion started by: berlin_germany
2 Replies
Login or Register to Ask a Question