Results 1 to 7 of 7
I've been playing around with couchDB and working on a script to create a specific type of document but the variables are giving me problems. Here's the current line I ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
- 10-24-2012 #1
Quoting Variables
I've been playing around with couchDB and working on a script to create a specific type of document but the variables are giving me problems. Here's the current line I have in my script:
curl -X PUT http://sandbox:5984/test/$UUID -d '{"One":"$first","Two":$second"}'
Obviously, it's outputting $first and $second instead of using the previously defined values. I can't figure out how to escape it propperly to give me the output that I want. assuming the variable values are first=bananas and second=apples, the actual command run by the script should be:
curl -X PUT http://sandbox:5984/test/$UUID -d '{"One":"bananas","Two":apples"}'
Also, these variables are initially being defined by the user through "read".
- 10-25-2012 #2Just Joined!
- Join Date
- May 2012
- Posts
- 43
You're missing a " at the start of $second.
- 10-25-2012 #3Trusted Penguin
- Join Date
- May 2011
- Posts
- 3,657
- 10-25-2012 #4
I don't think I can use that formatting. Couch is not accepting it as valid JSON
- 10-26-2012 #5Trusted Penguin
- Join Date
- May 2011
- Posts
- 3,657
i see. i'm not using couch, just a regular CGI parser. so how about this then? Replace the outer single quotes w/the double-quotes:
this allows the variables ($first, $second) to get expanded. single-quotes will prevent that.Code:curl -X PUT http://$URL -d "{One=$first,Two=$second}"
or, if for some reason, you need the quotes around the parameter values, you can escape them, e.g.:
Code:curl -X PUT http://$URL -d "{One=\"$first\",Two=\"$second\"}"
- 10-26-2012 #6
I definitely need the double quotes to appear around the variable. The problem with the second example you posted is that when I escape quotation marks, it reads escape slash as part of the string as well (it's not only escaping the quotation marks but passing the slash along to couch in addition to the quotation marks).
- 10-27-2012 #7Trusted Penguin
- Join Date
- May 2011
- Posts
- 3,657
I don't understand how that is possible. Is your script written in Bash or something else? Can you show a snippet of code that uses the curl command?
Assuming Bash, here is another angle:
Code:args="{One:\"$first\",Two:\"$second\"}" curl -X PUT http://localhost/cgi-bin/env.pl -d "$args"


Reply With Quote

