You are not logged in.

#1 2008-06-15 07:26:23

tony5429
Member
Registered: 2006-03-28
Posts: 1,017

Using Variables in Shell Scripts

I am trying to use a variable in a shell script like this....

callsign = N1ZK

wget 'http://aprs.fi/?call='.$callsign.'&c=map'

But this doesn't seem to be working. Can anyone help me? I am sure it is something simple...

Offline

#2 2008-06-15 07:34:51

Allan
Pacman
From: Brisbane, AU
Registered: 2007-06-09
Posts: 11,365
Website

Re: Using Variables in Shell Scripts

You probably want this

callsign=N1ZK
wget http://aprs.fi/?call=${callsign}\&c=map

You needed to remove the spaces in the variable assignment.  You could continue using quotes around the url but you do not need the "." to join the strings.

Offline

#3 2008-06-15 13:16:53

ThomasAdam
Member
From: Southampton, England
Registered: 2005-10-26
Posts: 148

Re: Using Variables in Shell Scripts

Allan wrote:

You probably want this

callsign=N1ZK
wget http://aprs.fi/?call=${callsign}\&c=map

You needed to remove the spaces in the variable assignment.  You could continue using quotes around the url but you do not need the "." to join the strings.

No -- remove the quotes -- look at the example -- single quotes as the OP had it doesn't allow for variable interpolation.

-- Thomas Adam

Offline

#4 2008-06-15 13:40:55

shining
Pacman Developer
Registered: 2006-05-10
Posts: 2,043

Re: Using Variables in Shell Scripts

ThomasAdam wrote:

No -- remove the quotes -- look at the example -- single quotes as the OP had it doesn't allow for variable interpolation.

Could you try again in english please?
There is nothing wrong with what Allan said.
Though he suggested keeping using quotes around the url, and I would recommend that as well :

callsign=N1ZK
wget "http://aprs.fi/?call=${callsign}\&c=map"

pacman roulette : pacman -S $(pacman -Slq | LANG=C sort -R | head -n $((RANDOM % 10)))

Offline

#5 2008-06-15 13:45:20

ThomasAdam
Member
From: Southampton, England
Registered: 2005-10-26
Posts: 148

Re: Using Variables in Shell Scripts

shining wrote:
ThomasAdam wrote:

No -- remove the quotes -- look at the example -- single quotes as the OP had it doesn't allow for variable interpolation.

Could you try again in english please?
There is nothing wrong with what Allan said.

Oh sure.  It's just that in the original example, we see:

wget 'http://aprs.fi/?call='.$callsign.'&c=map'

SInce it was never pointed out to change the quotes to double quotes, just using single ones wouldn't help here to interpolate "$callsign".

I hope that's English enough for you.

-- Thomas Adam

Offline

#6 2008-06-15 13:50:30

Allan
Pacman
From: Brisbane, AU
Registered: 2007-06-09
Posts: 11,365
Website

Re: Using Variables in Shell Scripts

ThomasAdam wrote:

SInce it was never pointed out to change the quotes to double quotes, just using single ones wouldn't help here to interpolate "$callsign".

Yeah, but this does work...

wget 'http://aprs.fi/?call='${callsign}'&c=map'

So as I said, he can keep the quotes but remove the "." separating everything.  Ugly but it works...

Offline

#7 2008-06-15 13:54:14

ThomasAdam
Member
From: Southampton, England
Registered: 2005-10-26
Posts: 148

Re: Using Variables in Shell Scripts

Allan wrote:
ThomasAdam wrote:

SInce it was never pointed out to change the quotes to double quotes, just using single ones wouldn't help here to interpolate "$callsign".

Yeah, but this does work...

wget 'http://aprs.fi/?call='${callsign}'&c=map'

So as I said, he can keep the quotes but remove the "." separating everything.  Ugly but it works...

Oh *right* -- I must be blind.

Yes, ugly.  Why not wrap the whole thing in double quotes?  The single quotes don't serve a purpose in this instance.

My mistake.

-- Thomas Adam

Offline

Board footer

Powered by FluxBB