Bash variable problem: cURL -b parameter (string form e.g. "name=value;n2=v2")
Hi, sorry this is a newbie questions I fear:
I am trying to update one of my bash scripts to work with Firefox3's sqlite cookie format.
I can extract the cookie values but am trying to pass them as a string variable to the -b parameter in curl, rather than as a reference to a netscape format cookie.txt file.
The curl MAN page explains that this is possible and it works if I pass the hardcoded string cURL -b"pass=xyz;userID=123", but when I pass the same data as a variable it breaks. I've tried all manner of escaping, quoting, echoing the variable and using brackets and backticks but am really stuck.
I'm building the string by querying sqlite for the individual values:
so my curl command looks like:
I am trying to avoid the need to generate a cookies.txt file from the sqlite queries and just build a string value for the -b parameter.
Any help or pointers much appreciated.
This problem comes up frequently, as new users are not familiar with how and when the shell splits words. You have also discovered, and may not yet realize it, that echo is not a good too to show what the shell sees. Use set -x instead before your assignment, and learn what its output means and indicates.
This will also help:
See Question 8, Homework, Week 4 "Arguments": http://cis68b1.mikecappella.com/
Thanks, Mr C :)
The URL is a great one for me. I haven't had time to work through the course yet, but it looks very useful. Suffice to say, I don't know enough of the building blocks to understand all the code in lesson 4, as I've skimmed a couple of UNIX 101 type courses but bounced off power-globbing, iteration and such topics without really understanding them. Amazing (to me) that I've actually written some functional, useful scripts with such limited understanding and have so far avoided any major catastrophes ;)
After my previous post I'd done a bit more digging and discovered the set -x debug tool, which was enough for me to see that as I'd suspected, echo was not accurately representing the variable. However, just as you suggest, I now need to learn the meaning of its output, which will require some further experimentation.
Unfortunately, I only get time to do this stuff in the last couple of hours of consciousness each day after coming home from working on VB and SQL, so my brain is not at its best.
Thanks again for providing such a useful reference. I'll post on this thread again when I've solved my little problem.
You're welcome. Glad you find the material useful. Every so often, I consider updating the material to make the lessons more accessible, and geared towards bash.
|All times are GMT -5. The time now is 07:02 AM.|