> On Mon, May 9, 2011 at 12:00 PM, Xi Shen <davidshen84@googlemail.com>
> wrote:
> > On Mon, May 9, 2011 at 4:31 PM, Pandu Poluan <pandu@poluan.info> wrote:
> > > On 2011-05-09, Xi Shen <davidshen84@googlemail.com> wrote:
> > >> My script looks like:
> > >>
> > >> url="http://mypage"
> > >> curl_opts="-x '"
> > >> curl $url -d "mydata" $curl_opts
> > >>
> > >> If I execute it, I got an error from curl, saying it cannot resolve
> > >> the proxy '.
> > >>
> > >> But If I modify the script to:
> > >>
> > >> url="http://mypage"
> > >> curl $url -d "mydata" -x '
> > >>
> > >> It works fine.
> > >>
> > >> I guess there's something wrong with the argument expansion. Just do
> > >> not know how to fix it. Please help.
Do as you tried first, but add an eval:
eval curl "$url" -d "mydata" $curl_opts
> > I have replied you before.
>
> What I have sent you is the solution to your problems.
> Try to run what I told you.
> I ran it successfully on my comp.
> curl_opts=-x ""
This gives a "command not found" error, as bash tries to execute the empty
command "". Are you using another shell?
Wonko
05-09-2011, 10:45 AM
"JDM"
bash script error
He
------Original Message------
From: Alex Schuster
To: gentoo-user@lists.gentoo.org
ReplyTo: gentoo-user@lists.gentoo.org
Subject: Re: [gentoo-user] [OT] bash script error
Sent: 9 May 2011 11:36
Kfir Lavi writes:
> On Mon, May 9, 2011 at 12:00 PM, Xi Shen <davidshen84@googlemail.com>
> wrote:
> > On Mon, May 9, 2011 at 4:31 PM, Pandu Poluan <pandu@poluan.info> wrote:
> > > On 2011-05-09, Xi Shen <davidshen84@googlemail.com> wrote:
> > >> My script looks like:
> > >>
> > >> url="http://mypage"
> > >> curl_opts="-x '"
> > >> curl $url -d "mydata" $curl_opts
> > >>
> > >> If I execute it, I got an error from curl, saying it cannot resolve
> > >> the proxy '.
> > >>
> > >> But If I modify the script to:
> > >>
> > >> url="http://mypage"
> > >> curl $url -d "mydata" -x '
> > >>
> > >> It works fine.
> > >>
> > >> I guess there's something wrong with the argument expansion. Just do
> > >> not know how to fix it. Please help.
Do as you tried first, but add an eval:
eval curl "$url" -d "mydata" $curl_opts
> > I have replied you before.
>
> What I have sent you is the solution to your problems.
> Try to run what I told you.
> I ran it successfully on my comp.
> curl_opts=-x ""
This gives a "command not found" error, as bash tries to execute the empty
command "". Are you using another shell?
Wonko
Sent from my BlackBerry® wireless device
05-09-2011, 12:06 PM
Kfir Lavi
bash script error
On Mon, May 9, 2011 at 1:36 PM, Alex Schuster <wonko@wonkology.org> wrote:
Kfir Lavi writes:
> On Mon, May 9, 2011 at 12:00 PM, Xi Shen <davidshen84@googlemail.com>
> wrote:
> > On Mon, May 9, 2011 at 4:31 PM, Pandu Poluan <pandu@poluan.info> wrote:
> > > On 2011-05-09, Xi Shen <davidshen84@googlemail.com> wrote:
I would probably even go one further and use quotes in the final line as well,
thus producing:
curl "${url}"-d "mydata" "${curl_opts}"
Please note that the single and double quotes have meanings as far as expansion.
Also, the guys on IRC (#bash) are quite helpful - a great resource in addition
to 'man bash'.
$0.02
Ben
----- Original Message ----
> From: Xi Shen <davidshen84@googlemail.com>
> To: gentoo-user <gentoo-user@lists.gentoo.org>
> Sent: Mon, May 9, 2011 1:44:58 AM
> Subject: [gentoo-user] [OT] bash script error
>
> It is not specific to Gentoo. But do not know where to search or post it
>
> My script looks like:
>
> url="http://mypage"
> curl_opts="-x '"
> curl $url -d "mydata" $curl_opts
>
> If I execute it, I got an error from curl, saying it cannot resolve
> the proxy '.
>
> But If I modify the script to:
>
> url="http://mypage"
> curl $url -d "mydata" -x '
>
> It works fine.
>
> I guess there's something wrong with the argument expansion. Just do
> not know how to fix it. Please help.
>
>
> --
> Best Regards,
> Xi Shen (David)
>
> http://twitter.com/davidshen84/
>
>
05-09-2011, 12:57 PM
BRM
bash script error
Well, I saw a lot of advice on this but no real solution - just some debugging
help.
At least from my own experience with Bash Scripting, I find that you can never
use enough braces when referencing variables.
I would probably even go one further and use quotes in the final line as well,
thus producing:
curl "${url}"-d "mydata" "${curl_opts}"
Please note that the single and double quotes have meanings as far as expansion.
Also, the guys on IRC (#bash) are quite helpful - a great resource in addition
to 'man bash'.
$0.02
Ben
----- Original Message ----
> From: Xi Shen <davidshen84@googlemail.com>
> To: gentoo-user <gentoo-user@lists.gentoo.org>
> Sent: Mon, May 9, 2011 1:44:58 AM
> Subject: [gentoo-user] [OT] bash script error
>
> It is not specific to Gentoo. But do not know where to search or post it
>
> My script looks like:
>
> url="http://mypage"
> curl_opts="-x '"
> curl $url -d "mydata" $curl_opts
>
> If I execute it, I got an error from curl, saying it cannot resolve
> the proxy '.
>
> But If I modify the script to:
>
> url="http://mypage"
> curl $url -d "mydata" -x '
>
> It works fine.
>
> I guess there's something wrong with the argument expansion. Just do
> not know how to fix it. Please help.
>
>
> --
> Best Regards,
> Xi Shen (David)
>
> http://twitter.com/davidshen84/
>
>
05-09-2011, 02:16 PM
Kevin McCarthy
bash script error
On Mon, May 09, 2011 at 01:44:58PM +0800, Xi Shen wrote:
> It is not specific to Gentoo. But do not know where to search or post it
>
> My script looks like:
>
> url="http://mypage"
> curl_opts="-x '"
> curl $url -d "mydata" $curl_opts
>
> If I execute it, I got an error from curl, saying it cannot resolve
> the proxy '.
>
While bash arrays probably aren't required for this, the following seems
to work OK:
On Mon, 09 May 2011, JDM wrote:
>Do as you tried first, but add an eval:
>eval curl "$url" -d "mydata" $curl_opts
eval is evil ...
-dnh
--
"Being disintegrated makes me ve-ry an-gry!" <huff, huff>
05-10-2011, 10:57 PM
David Haller
bash script error
Hello,
On Mon, 09 May 2011, Kevin McCarthy wrote:
>On Mon, May 09, 2011 at 01:44:58PM +0800, Xi Shen wrote:
>> It is not specific to Gentoo. But do not know where to search or post it
>>
>> My script looks like:
>>
>> url="http://mypage"
>> curl_opts="-x '"
>> curl $url -d "mydata" $curl_opts
>>
>> If I execute it, I got an error from curl, saying it cannot resolve
>> the proxy '.
>>
>
>While bash arrays probably aren't required for this, the following seems
>to work OK:
When using the bash anyway, arrays are the thing to use!
I can't find one. Seems to be some curl weirdness layered on top. Even
with
strace -eexecve curl "$url" -d "mydata" $curl_opts
and (quoted, escaped etc.) variations thereof, I haven't found a
version that works.
If you want to just DL some stuff, with POST, no proxy, why not use
wget?
wget --post-data="mydata" --no-proxy "$url"
(and if you want the result on stdout, just add '-O -', i.e.:
wget --post-data="mydata" --no-proxy -O - "$url"
). Or if you want the options as such:
url=...
wget_opts="--no-proxy -O -" ### special chars need to be
### once-escaped when using
### options/arguments with spaces,
### quotes etc.
post_data="foo=bar"
set -x
wget ${wget_opts} --post-data="$post_data" "$url"
### ^^^^^^^^^^^^ no quotes here, or use an array!
HTH,
-dnh
--
Doesn't it bother you, that we have to search for intelligent life
--- OUT THERE??