public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
* [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

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

Dear Sridhar Addagada,

In message <1327396047.99588.YahooMailNeo@web120201.mail.ne1.yahoo.com> you wrote:
>
> What is the behavior of test command when the variable is not present in the uboot env

It should be the same as in any other bourne compatible shell.

> set x

Note that "set" for "setenv" may or may not work, depending on your
command selection.

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

This should provoke an error from the "test" command which misses an
argument.

> in the above case I get Yes echoed back.

That's a bug then.  Patches welcome...

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

This should be possible like in any other shell...



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
Alan Turing thought about criteria to settle the question of  whether
machines  can think, a question of which we now know that it is about
as relevant as the question of whether submarines can swim.
                                                   -- Edsger Dijkstra

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

* [U-Boot] u-boot script "test"
  2012-01-24 10:43 ` Wolfgang Denk
@ 2012-01-24 11:30   ` Sridhar Addagada
  0 siblings, 0 replies; 4+ messages in thread
From: Sridhar Addagada @ 2012-01-24 11:30 UTC (permalink / raw)
  To: u-boot

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



________________________________
 From: Wolfgang Denk <wd@denx.de>
To: Sridhar Addagada <sridhar_a@yahoo.com> 
Cc: "u-boot at lists.denx.de" <u-boot@lists.denx.de> 
Sent: Tuesday, January 24, 2012 4:13 PM
Subject: Re: [U-Boot] u-boot script "test"
 
Dear Sridhar Addagada,

In message <1327396047.99588.YahooMailNeo@web120201.mail.ne1.yahoo.com> you wrote:
>
> What is the behavior of test command when the variable is not present in the uboot env

It should be the same as in any other bourne compatible shell.

> set x

Note that "set" for "setenv" may or may not work, depending on your
command selection.

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

This should provoke an error from the "test" command which misses an
argument.

> in the above case I get Yes echoed back.

That's a bug then.? Patches welcome...

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

This should be possible like in any other shell...



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
Alan Turing thought about criteria to settle the question of? whether
machines? can think, a question of which we now know that it is about
as relevant as the question of whether submarines can swim.
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?  -- Edsger Dijkstra

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

* [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

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