Re: eval usage
am 16.01.2008 20:36:27 von Icarus Sparry
On Wed, 16 Jan 2008 09:38:23 -0800, Brendan wrote:
> test -z "$L4ALLYRFile" && \
> L4ALLYRFile="N$opt$Year${monsday[1]}$Year${moneday[12]}.L4_Y R_
> $ext"
> eval L4ALLYRFile=$L4ALLYRFile
>
>
> Could some please explain to me what the eval command is doing in this
> context? Why assign a variable to itself?
Well, it does one level of expansion. E.g.
$ A='xx$(date +%a)'
$ echo "$A"
xx$(date +%a)
$ eval A=$A
$ echo "$A"
xxWed
What it does in your context is hard to tell, without knowing the
possible values that the L4ALLYRFile variable can have, and if it is
empty the possible values that the other 6 variables mentioned can have.
Re: eval usage
am 16.01.2008 20:48:06 von Brendan
Okay. So in this case it is done to expand the ${monsday[1]} and $
{monsday[12]}?
Isn't there a more straight forward way of doing this? i.e. ${!
monsday[1]}
On Jan 16, 3:36=A0pm, Icarus Sparry wrote:
> On Wed, 16 Jan 2008 09:38:23 -0800, Brendan wrote:
> > test -z "$L4ALLYRFile" && \
> > =A0 =A0 =A0 =A0 L4ALLYRFile=3D"N$opt$Year${monsday[1]}$Year${moneday[12]=
}.L4_YR_
> > $ext"
> > eval L4ALLYRFile=3D$L4ALLYRFile
>
> > Could some please explain to me what the eval command is doing in this
> > context? Why assign a variable to itself?
>
> Well, it does one level of expansion. E.g.
>
> $ A=3D'xx$(date +%a)'
> $ echo "$A"
> xx$(date +%a)
> $ eval A=3D$A
> $ echo "$A"
> xxWed
>
> What it does in your context is hard to tell, without knowing the
> possible values that the L4ALLYRFile variable can have, and if it is
> empty the possible values that the other 6 variables mentioned can have.
Re: eval usage
am 16.01.2008 20:59:16 von Icarus Sparry
On Wed, 16 Jan 2008 11:48:06 -0800, Brendan wrote:
> Okay. So in this case it is done to expand the ${monsday[1]} and $
> {monsday[12]}?
Maybe. It depends on what you are asking. It is not needed to do one
level of replacement
$ A='red'
$ B="hi $A"
$ echo "$B"
hi red
In your script it is probably a bug, but as I said without knowing the
allowed values for the 7 variable involved we can not be sure.
> Isn't there a more straight forward way of doing this? i.e. ${!
> monsday[1]}
${!variable} is a bash feature, and is slightly different.
A='$B'
B='hello'
echo "${!A}"
in bash gives nothing
A='B'
echo "${!A}"
in bash gives "hello". It does one level of indirection on the name, it
does not do a full evaluation on the string.
> On Jan 16, 3:36Â pm, Icarus Sparry wrote:
>> On Wed, 16 Jan 2008 09:38:23 -0800, Brendan wrote:
>> > test -z "$L4ALLYRFile" && \
>> > Â Â Â Â L4ALLYRFile="N$opt$Year${monsday[1]}$Year${moneday
[12]}.L4_YR_
>> > $ext"
>> > eval L4ALLYRFile=$L4ALLYRFile
>>
>> > Could some please explain to me what the eval command is doing in
>> > this context? Why assign a variable to itself?
>>
>> Well, it does one level of expansion. E.g.
>>
>> $ A='xx$(date +%a)'
>> $ echo "$A"
>> xx$(date +%a)
>> $ eval A=$A
>> $ echo "$A"
>> xxWed
>>
>> What it does in your context is hard to tell, without knowing the
>> possible values that the L4ALLYRFile variable can have, and if it is
>> empty the possible values that the other 6 variables mentioned can
>> have.