BASH variables, quotation marks and cURL struggles
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Introduction to Linux - A Hands on Guide
This guide was created as an overview of the Linux Operating System, geared toward new users as an exploration tour and getting started guide, with exercises at the end of each chapter.
For more advanced trainees it can be a desktop reference, and a collection of the base knowledge needed to proceed with system and network administration. This book contains many real life examples derived from the author's experience as a Linux system and network administrator, trainer and consultant. They hope these examples will help you to get a better understanding of the Linux system and that you feel encouraged to try out things on your own.
Click Here to receive this Complete Guide absolutely free.
Now comes the weird part:
When I invoke cURL using the data string directly (i.e. without going through that variable), everything works and the data is transmitted correctly. If however I go through that variable as an argument to cURL, although it contains the exact same string, the whole thing will break (no data arrives at the server because cURL interprets part of the string as a server URL, obviously because the double quotation marks disappeared somehow and it interprets everything that is not a whitespace as an argument).
Shouldn't these two approaches result in the exact same thing? ^^ Am I missing something?
there will be three params to echo with contents some and te xt and here.
But if you use
DOCDATA='some "te xt" here'
there will be only one param to echo, with contents some "te xt" here.
If they should stay individual parameters, you must leave out the quotes around $DOCDATA,
so this will again pass three params to the echo command:
might this help? Maybe you could post the whole script (or at least the part constructing and using the DOCDATA var)
then I could have a better look at it.
yes, I am aware of the difference between single and double quotation marks. I want that argument string to not be broken into several parts, but passed to curl "as-is". The odd thing is, when I echo that variable, it prints exactly what I want. I mean, I can even copy and paste that output to curl as an argument and then it will work. It just doesn't work when I go through that variable.
The thread I opened there actually covered a different problem, but along the road I also asked the same question there. I wasn't aware that strings in variables, even when surrounded with single quotation marks, will still be broken into words when passed as arguments. That explains a lot of course :-)
Last edited by matthias_k; 03-25-2008 at 12:20 AM.
gives the error. The first part is somewhat correct because the shell assigns a value to the variable "upload" then try to execute the "-L" command. Ok... solution: escape the ampersand and strip away the eval command.
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 "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:
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'"`
(Edit: Apologies, I just noticed that I mis-identified the backticks for hard-quotes. Still, using a function should make the command more robust. I've added an example capture to variable to the code below. And remember, $(..) is highly recommended over `..`.)
Variables are for storing data, not code. Don't try to put commands in them and expect them to work.
The problem has something to do with the format of the curl command then. The error message is coming from it, in any case. It's unlikely that the function format itself has anything to do with it.
Make sure your variables are set correctly. Try putting an echo in front of the command so you can see exactly what would be executed. Or use #!/bin/bash -x at the top of the script to get debugging-style output.