Share your knowledge at the LQ Wiki.
Go Back > Forums > Other *NIX Forums > Other *NIX
User Name
Other *NIX This forum is for the discussion of any UNIX platform that does not have its own forum. Examples would include HP-UX, IRIX, Darwin, Tru64 and OS X.


  Search this Thread
Old 07-08-2008, 04:24 PM   #1
LQ Newbie
Registered: Jul 2008
Posts: 5

Rep: Reputation: 0
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:
  ffcf=[path to cookies.sqlite]
  thepass=`sqlite3 "$ffcf" "select value from moz_cookies where host='[host string]' and name='pass'"`
  theUID=`sqlite3 "$ffcf" "select value from moz_cookies where host='[host string]' and name='uid'"`
then concatenating them into a variable
  echo "Input Cookie String:" "$inputcookiefn"
which looks right when I echo it back

so my curl command looks like:

curl -s -S -b "$inputcookies"  -c newcookies.txt -A 'Mozilla/4.0' [website URL here] > testresults.htm
The cURL command completes, but the site doesn't accept the cookies when passed as a variable, although it accepts the hardcoded string as shown above, which _appears_ to be identical.

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.

Last edited by sithemac; 07-08-2008 at 04:43 PM.
Old 07-08-2008, 06:12 PM   #2
Mr. C.
Senior Member
Registered: Jun 2008
Posts: 2,529

Rep: Reputation: 61
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":

Last edited by Mr. C.; 07-09-2008 at 06:12 PM.
Old 07-09-2008, 05:56 PM   #3
LQ Newbie
Registered: Jul 2008
Posts: 5

Original Poster
Rep: Reputation: 0
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.

Last edited by sithemac; 07-09-2008 at 06:04 PM. Reason: to do justice to the help given
Old 07-09-2008, 06:15 PM   #4
Mr. C.
Senior Member
Registered: Jun 2008
Posts: 2,529

Rep: Reputation: 61
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.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
c++ - "index" is a global scope variable in <string>???? BrianK Programming 2 03-18-2008 08:05 PM
Standard commands give "-bash: open: command not found" even in "su -" and "su root" mibo12 Linux - General 4 11-11-2007 10:18 PM
How I can Convert 4 byte IP to an IP string of form ("") touqeer.ansar Programming 2 07-16-2006 11:02 PM
bash cripting function to "identify" any char in a string? minike Programming 8 02-01-2006 09:45 AM
Bash Script: Problem running variable command containing "" Paasan Programming 2 01-21-2004 01:45 AM > Forums > Other *NIX Forums > Other *NIX

All times are GMT -5. The time now is 11:23 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration