[dundee] Help with Bash Shell

'Gary Short' gary at garyshort.org
Thu Mar 31 00:23:21 UTC 2011


All,

 

I think the Bash Shell maybe the worst programming language I've ever used.
I'm trying to do something so simple and yet it's eluding me. I have a file
(results) which holds JSON documents, I want to take the first line of that
file and pass it to a bash script that will store it in couchdb, simple.
You'd think! So I have this line

 

Head -n1 | store_to_couch.sh

 

Which will pass the first line to the script, that much works

 

Then my script....

 

#!/bin/bash

 

While read data; do

   curl -X PUT http://couchdb:port/db -d $data

done

 

which works, after a fashion, in as much as it sends the JSON document to
couchdb, but it fails  'cos the quotes are not... well quoted, if you see
what I mean. What I need is the contents of $data to be wrapped in single
quotes, but I can't figure out for the life of me how to do it. It's not ' +
$data + ' for example, as it would be in other languages.

 

Can anyone help me?

 

Thanks,

Gary

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.lug.org.uk/pipermail/dundee/attachments/20110331/1b4c4851/attachment.htm>


More information about the dundee mailing list