public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: James Chargin <jimccrown@gmail.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] u-boot script "test"
Date: Wed, 25 Jan 2012 08:22:04 -0800	[thread overview]
Message-ID: <4F202C2C.9030905@gmail.com> (raw)

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

             reply	other threads:[~2012-01-25 16:22 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-01-25 16:22 James Chargin [this message]
  -- strict thread matches above, loose matches on Subject: below --
2012-01-24  9:07 [U-Boot] u-boot script "test" Sridhar Addagada
2012-01-24 10:43 ` Wolfgang Denk
2012-01-24 11:30   ` Sridhar Addagada

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4F202C2C.9030905@gmail.com \
    --to=jimccrown@gmail.com \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox