Register
It is currently Mon Sep 22, 2014 2:12 am

using curl in bash


All times are UTC - 6 hours


Post new topic Reply to topic  [ 5 posts ] 
Author Message
 PostPosted: Tue May 28, 2013 10:47 am   

Joined: Tue May 28, 2013 10:38 am
Posts: 3
I use curl in my bash-script

Code:
the_product_id="924600454"
tmp_data_key="etnOrduglx"
the_title_id="BASLER -"
curl -XPUT 'http://localhost:9200/products/product/1' -d '{"ProductID" : "'$the_product_id'","data_key" : "'$tmp_data_key'","Title" : "'$the_title_id'","ProductPrice" : 0,"Discount" : 0,"OldPrice" : 0}'


And I get

Code:
Error:
curl: option -"","ProductPrice" : 0,"Discount" : 0,"OldPrice" : 0}: is unknown
curl: try 'curl --help' or 'curl --manual' for more information


–°an anybody tell me why?
How to pass the text to the command?
Thanks a lot!


Top
 Profile  
 PostPosted: Tue May 28, 2013 5:19 pm   

Joined: Mon Mar 02, 2009 3:03 am
Posts: 548
because you're mixing quotes.
the shell reads from the first single quote to the second, from the third to the fourth, and so on, not from the first to the last, then between them.

maybe this way:
Code:
curl -XPUT 'http://localhost:9200/products/product/1' -d "{'ProductID : '\"$the_product_id\"','data_key' : '\"$tmp_data_key\"','Title' : '\"$the_title_id\"','ProductPrice' : 0,'Discount' : 0,'OldPrice' : 0}"


Top
 Profile  
 PostPosted: Wed May 29, 2013 1:17 am   

Joined: Tue May 28, 2013 10:38 am
Posts: 3
no
It's not work.
when I try run

Code:
test_save="curl -XPUT 'http://localhost:9200/products/product/3' -d '{\"ProductID\" : \"$the_product_id\",\"data_key\" : \"$tmp_data_key\",\"Title\" : \"${test}\",\"ProductPrice\" : 0,\"Discount\" : 0,\"OldPrice\" : 0}'"
echo $test_save
echo $($test_save)


I get
Code:
curl -XPUT 'http://localhost:9200/products/product/3' -d '{"ProductID" : "924600454","data_key" : "IwAajQlZxy","Title" : "BASLER -","ProductPrice" : 0,"Discount" : 0,"OldPrice" : 0}'
curl: option -","ProductPrice": is unknown
curl: try 'curl --help' or 'curl --manual' for more information


But when I tried run
Code:
curl -XPUT 'http://localhost:9200/products/product/3' -d '{"ProductID" : "924600454","data_key" : "IwAajQlZxy","Title" : "BASLER -","ProductPrice" : 0,"Discount" : 0,"OldPrice" : 0}'

from command line - it's work.


Top
 Profile  
 PostPosted: Wed May 29, 2013 1:37 am   

Joined: Mon Mar 02, 2009 3:03 am
Posts: 548
yes, I've made some mistakes in my quoting.
any way, you don't think too hard, do you?

Code:
$ var="blah blah blah"
$ echo "$var"
blah blah blah
$ echo "'$var'"
'blah blah blah'
$ echo "\"$var\""
"blah blah blah"
$ echo '"var$"'
"$var"


Top
 Profile  
 PostPosted: Wed May 29, 2013 1:55 am   

Joined: Tue May 28, 2013 10:38 am
Posts: 3
I have tried these options
Code:
echo "$the_title_id"
echo "'$the_title_id'"
echo "\"$the_title_id\""
echo '"the_title_id$"'


It's work when the_title_id="BASLER"
But It's not work when the_title_id="BASLER - "
think it's because of the dashes


Top
 Profile  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP