Find the answer to your Linux question:
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.
  1. #1
    Linux User cheesecake42's Avatar
    Join Date
    Jan 2007
    Location
    Orlando, FL
    Posts
    370

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

  2. #2
    Just Joined!
    Join Date
    May 2012
    Posts
    43
    You're missing a " at the start of $second.

  3. #3
    Trusted Penguin
    Join Date
    May 2011
    Posts
    4,353
    Quote Originally Posted by cheesecake42 View Post
    curl -X PUT http://sandbox:5984/test/$UUID -d '{"One":"bananas","Two":apples"}'
    for some reason, passing the data like that (enclosed in curlies) didn't work for me. but this does:

    Code:
    curl -X PUT http://$URL -d One="$first" -d Two="$second"

  4. $spacer_open
    $spacer_close
  5. #4
    Linux User cheesecake42's Avatar
    Join Date
    Jan 2007
    Location
    Orlando, FL
    Posts
    370
    I don't think I can use that formatting. Couch is not accepting it as valid JSON

  6. #5
    Trusted Penguin
    Join Date
    May 2011
    Posts
    4,353
    Quote Originally Posted by cheesecake42 View Post
    I don't think I can use that formatting. Couch is not accepting it as valid JSON
    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:

    Code:
    curl -X PUT http://$URL -d "{One=$first,Two=$second}"
    this allows the variables ($first, $second) to get expanded. single-quotes will prevent that.

    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\"}"

  7. #6
    Linux User cheesecake42's Avatar
    Join Date
    Jan 2007
    Location
    Orlando, FL
    Posts
    370
    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).

  8. #7
    Trusted Penguin
    Join Date
    May 2011
    Posts
    4,353
    Quote Originally Posted by cheesecake42 View Post
    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).
    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"

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •