Gentoo Archives: gentoo-user

From: BRM <bm_witness@×××××.com>
To: gentoo-user@l.g.o
Subject: Re: [gentoo-user] [OT] bash script error
Date: Mon, 09 May 2011 12:58:55
Message-Id: 540740.63121.qm@web39308.mail.mud.yahoo.com
In Reply to: [gentoo-user] [OT] bash script error by Xi Shen
1 Well, I saw a lot of advice on this but no real solution - just some debugging
2 help.
3
4 At least from my own experience with Bash Scripting, I find that you can never
5 use enough braces when referencing variables.
6
7 So, the script should read:
8
9 url="http://mypage"
10 curl_opts="-x"
11 curl ${url} -d \"mydata\" ${curl_opts}
12
13
14 I would probably even go one further and use quotes in the final line as well,
15 thus producing:
16
17 curl "${url}"-d \"mydata\" "${curl_opts}"
18
19 Please note that the single and double quotes have meanings as far as expansion.
20
21 Also, the guys on IRC (#bash) are quite helpful - a great resource in addition
22 to 'man bash'.
23
24 $0.02
25
26 Ben
27
28
29 ----- Original Message ----
30 > From: Xi Shen <davidshen84@××××××××××.com>
31 > To: gentoo-user <gentoo-user@l.g.o>
32 > Sent: Mon, May 9, 2011 1:44:58 AM
33 > Subject: [gentoo-user] [OT] bash script error
34 >
35 > It is not specific to Gentoo. But do not know where to search or post it :)
36 >
37 > My script looks like:
38 >
39 > url="http://mypage"
40 > curl_opts="-x ''"
41 > curl $url -d \"mydata\" $curl_opts
42 >
43 > If I execute it, I got an error from curl, saying it cannot resolve
44 > the proxy ''.
45 >
46 > But If I modify the script to:
47 >
48 > url="http://mypage"
49 > curl $url -d \"mydata\" -x ''
50 >
51 > It works fine.
52 >
53 > I guess there's something wrong with the argument expansion. Just do
54 > not know how to fix it. Please help.
55 >
56 >
57 > --
58 > Best Regards,
59 > Xi Shen (David)
60 >
61 > http://twitter.com/davidshen84/
62 >
63 >