public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
* [U-Boot] u-boot script "test"
@ 2012-01-25 16:22 James Chargin
  0 siblings, 0 replies; 4+ messages in thread
From: James Chargin @ 2012-01-25 16:22 UTC (permalink / raw)
  To: u-boot

In message <1327404627.60813.YahooMailNeo@web120202.mail.ne1.yahoo.com>

> For now i got around this problem with a negative test
> set x
>
> if test $x != 1 then echo "No"; else echo "Yes"; fi
>
> with this if x is not present i get No, even in the case when x is
> present and set any other value (not 1)
> when i do "set x 1" and run the test again i get "Yes"
>
> Thanks
> Sridhar

I've experienced a similar situation. For now, I'm using U-Boot 2010.12.
I want to test existence of environment var without any console output
about the result, only control of conditional statement. I've found that
the following provides what I need, even though it is a bit hackish.

My configuration defines CONFIG_SYS_DEVICE_NULLDEV so I can redirect
stdout and hide console output during existence testing.

=> setenv stderr nulldev
=> if printenv a; then echo yes; else echo no;fi
## Error: "a" not defined
no
=> coninfo
List of available devices:
serial   80000003 SIO stdin stdout
nulldev  80000003 SIO stderr

This seems a bug, the error message goes to stdout, rather than stderr;
but you decide how you think error messages should work. To work with
this as it is:

=> setenv t 'setenv stdout nulldev;if printenv a; then setenv stdout
serial; echo set; true; else setenv stdout serial;echo not set;false; fi'
=>
=> printenv a
## Error: "a" not defined
=> run t
not set
=> setenv a 1
=> run t
set
=> run t && echo 2
set
2
=> setenv a
=> run t && echo 2
not set
=>

Notice that use of printenv does not expand the environment variable so
there is never any issue with what that expands to.

If the hush shell is present, a hush variable can be used as a
"parameter" to the testing script

=> setenv t 'setenv stdout nulldev;if printenv $var;then setenv stdout
serial;true;else setenv stdout serial;false;fi'
=>
=> setenv b
=> if var=b;run t; then echo yes; else echo no; fi
no
=> setenv b 1
=> if var=b;run t; then echo yes; else echo no; fi
yes
=>

I hope this is helpful.

Jim

^ permalink raw reply	[flat|nested] 4+ messages in thread
* [U-Boot] u-boot script "test"
@ 2012-01-24  9:07 Sridhar Addagada
  2012-01-24 10:43 ` Wolfgang Denk
  0 siblings, 1 reply; 4+ messages in thread
From: Sridhar Addagada @ 2012-01-24  9:07 UTC (permalink / raw)
  To: u-boot

What is the behavior of test command when the variable is not present in the uboot env

set x
if test $x = 1; then echo "Yes"; else echo "No"; fi

in the above case I get Yes echoed back.

Is there any way to test the presence of a variable in uboot script?

Thanks
Sridhar

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

end of thread, other threads:[~2012-01-25 16:22 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-01-25 16:22 [U-Boot] u-boot script "test" James Chargin
  -- strict thread matches above, loose matches on Subject: below --
2012-01-24  9:07 Sridhar Addagada
2012-01-24 10:43 ` Wolfgang Denk
2012-01-24 11:30   ` Sridhar Addagada

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox