All of lore.kernel.org
 help / color / mirror / Atom feed
* [U-Boot] set and test a local variable in a script
@ 2014-11-22 18:23 Andreas Neubacher
  2014-11-22 22:56 ` Wolfgang Denk
  0 siblings, 1 reply; 4+ messages in thread
From: Andreas Neubacher @ 2014-11-22 18:23 UTC (permalink / raw)
  To: u-boot

hi,

i'm trying to set a local variable and test the variable in an 
if-then-else script ...
but it's somehow a bit weird!?

- set variable "nea" to 0
- create a script "x" and run .... OK
- modify variable "nea" to 1
- run script "x" again ... NOK?!

... what i'm doing wrong  -  the behavior is the same with 2013.10 and 
2014.01



 >U-Boot# nea=0
 >U-Boot# setenv x "if itest 1 -eq $nea; then echo var1; else echo var0; 
fi;"
 >U-Boot# run x
 >var0
 >U-Boot# nea=1
 >U-Boot# run x
 >var0            <<<<<----- so now i should get the "var1" as a result
 >U-Boot# echo $nea
 >1

 >U-Boot# setenv x "if itest 1 -eq $nea; then echo var1; else echo var0; 
fi;"
 >U-Boot# run x
 >var1          <<<<<------- after i set the script "x" again it's 
working ... ?!


br & thx for any hint,
Andy

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [U-Boot] set and test a local variable in a script
  2014-11-22 18:23 [U-Boot] set and test a local variable in a script Andreas Neubacher
@ 2014-11-22 22:56 ` Wolfgang Denk
  2014-11-23 16:56   ` Andreas Neubacher
  0 siblings, 1 reply; 4+ messages in thread
From: Wolfgang Denk @ 2014-11-22 22:56 UTC (permalink / raw)
  To: u-boot

Dear Andreas,

In message <5470D48C.1080103@gmx.at> you wrote:
> 
> i'm trying to set a local variable and test the variable in an 
> if-then-else script ...
> but it's somehow a bit weird!?

Not really weird; you just have to be a bit careful about quoting
rules...

> - set variable "nea" to 0
> - create a script "x" and run .... OK
> - modify variable "nea" to 1
> - run script "x" again ... NOK?!
> 
> ... what i'm doing wrong  -  the behavior is the same with 2013.10 and 
> 2014.01

...and it would be the same if you were testing with a regular shell on
the Linux command line.

Actually this is something I always recommend: if you see some strange
behaviour, first try to do the same in a standard shell environment,
and debug it there.


>  >U-Boot# nea=0
>  >U-Boot# setenv x "if itest 1 -eq $nea; then echo var1; else echo var0; 
> fi;"

It would have been a good idea here todo a "printenv x" to check what
was actually stored in the variable - this would have shown your
problem.  The thing is, you want to keep the '$nea' notation in the
variable, so you can evaluate the variable when you run that macro.
However, inside double quotes (") variable substitution takes place,
so above command is equivalent to

    setenv x "if itest 1 -eq 0; then echo var1; else echo var0; fi;"

>  >U-Boot# run x
>  >var0
>  >U-Boot# nea=1
>  >U-Boot# run x
>  >var0            <<<<<----- so now i should get the "var1" as a result
>  >U-Boot# echo $nea
>  >1
 
Use printenv to verify what is stored in the variable x, and you will
understand this.


Best regards,

Wolfgang Denk

-- 
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
Today is the yesterday you worried about tomorrow.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [U-Boot] set and test a local variable in a script
  2014-11-22 22:56 ` Wolfgang Denk
@ 2014-11-23 16:56   ` Andreas Neubacher
  2014-11-23 17:47     ` Wolfgang Denk
  0 siblings, 1 reply; 4+ messages in thread
From: Andreas Neubacher @ 2014-11-23 16:56 UTC (permalink / raw)
  To: u-boot

hi,

many, many, many thx for your quick response ... now it works, and i 
know why it hasn't  :)

br,
Andy


On 22.11.2014 23:56, Wolfgang Denk wrote:
> Dear Andreas,
>
> In message <5470D48C.1080103@gmx.at> you wrote:
>> i'm trying to set a local variable and test the variable in an
>> if-then-else script ...
>> but it's somehow a bit weird!?
> Not really weird; you just have to be a bit careful about quoting
> rules...
>
>> - set variable "nea" to 0
>> - create a script "x" and run .... OK
>> - modify variable "nea" to 1
>> - run script "x" again ... NOK?!
>>
>> ... what i'm doing wrong  -  the behavior is the same with 2013.10 and
>> 2014.01
> ...and it would be the same if you were testing with a regular shell on
> the Linux command line.
>
> Actually this is something I always recommend: if you see some strange
> behaviour, first try to do the same in a standard shell environment,
> and debug it there.
>
>
>>   >U-Boot# nea=0
>>   >U-Boot# setenv x "if itest 1 -eq $nea; then echo var1; else echo var0;
>> fi;"
> It would have been a good idea here todo a "printenv x" to check what
> was actually stored in the variable - this would have shown your
> problem.  The thing is, you want to keep the '$nea' notation in the
> variable, so you can evaluate the variable when you run that macro.
> However, inside double quotes (") variable substitution takes place,
> so above command is equivalent to
>
>      setenv x "if itest 1 -eq 0; then echo var1; else echo var0; fi;"
>
>>   >U-Boot# run x
>>   >var0
>>   >U-Boot# nea=1
>>   >U-Boot# run x
>>   >var0            <<<<<----- so now i should get the "var1" as a result
>>   >U-Boot# echo $nea
>>   >1
>   
> Use printenv to verify what is stored in the variable x, and you will
> understand this.
>
>
> Best regards,
>
> Wolfgang Denk
>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [U-Boot] set and test a local variable in a script
  2014-11-23 16:56   ` Andreas Neubacher
@ 2014-11-23 17:47     ` Wolfgang Denk
  0 siblings, 0 replies; 4+ messages in thread
From: Wolfgang Denk @ 2014-11-23 17:47 UTC (permalink / raw)
  To: u-boot

Dear Andreas,

In message <547211BA.7080603@gmx.at> you wrote:
> 
> many, many, many thx for your quick response ... now it works, and i 
> know why it hasn't  :)

I'm glad I was able to help.

Best regards,

Wolfgang Denk

-- 
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
If the car industry behaved like the computer industry over the  last
30  years, a Rolls-Royce would cost $5, get 300 miles per gallon, and
blow up once a year killing all passengers inside.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2014-11-23 17:47 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-11-22 18:23 [U-Boot] set and test a local variable in a script Andreas Neubacher
2014-11-22 22:56 ` Wolfgang Denk
2014-11-23 16:56   ` Andreas Neubacher
2014-11-23 17:47     ` Wolfgang Denk

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.