public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
* [U-Boot-Users] test variable existence in hush
@ 2005-08-22 10:57 Andreas Engel
  2005-08-22 12:21 ` Wolfgang Denk
  0 siblings, 1 reply; 3+ messages in thread
From: Andreas Engel @ 2005-08-22 10:57 UTC (permalink / raw)
  To: u-boot

Hi,

can anyone confirm that this is a bug in the hush shell: both

 test -n "$foo" && echo yes

and

 test -z "$foo" && echo yes

result in nothing echoed if foo is not defined. If, on the other hand,
foo is defined to a string containing blanks, both commands will echo
yes.

Is there another way to check the existence of a variable?

Regards,
  Andreas Engel 

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

* [U-Boot-Users] test variable existence in hush
  2005-08-22 10:57 [U-Boot-Users] test variable existence in hush Andreas Engel
@ 2005-08-22 12:21 ` Wolfgang Denk
  2005-08-22 13:01   ` Andreas Engel
  0 siblings, 1 reply; 3+ messages in thread
From: Wolfgang Denk @ 2005-08-22 12:21 UTC (permalink / raw)
  To: u-boot

In message <20050822125758.00001da8@idefix> you wrote:
> 
> can anyone confirm that this is a bug in the hush shell: both

>  test -n "$foo" && echo yes

I cannot confirm this. The only part of hush which is  involved  here
is the && processing which works fine for me..

"test" is NOT a hush builtin.

For example all I get is:

	=> test -n "$foo" && echo yes
	Unknown command 'test' - try 'help'

> result in nothing echoed if foo is not defined. If, on the other hand,
> foo is defined to a string containing blanks, both commands will echo
> yes.
> 
> Is there another way to check the existence of a variable?

Sure:

TRAB # foo=
TRAB # test -n "$foo" && echo yes
TRAB # test -n "$foo" || echo no
no
TRAB # test "$foo" && echo yes
TRAB # test "$foo" || echo no
no
TRAB # foo=dummy
TRAB # test -n "$foo" && echo yes
yes
TRAB # test -n "$foo" || echo no
TRAB # test "$foo" && echo yes
TRAB # test "$foo" || echo no
no



THe only problem I see is with "test -z":

	TRAB # foo=
	TRAB # test -z "$foo" && echo yes
	TRAB # test -z "$foo" || echo no
	no
but
	TRAB # test -z "" && echo yes
	yes
	TRAB # test -z "" || echo no
	TRAB # 



Patches welcome.

Best regards,

Wolfgang Denk

-- 
Software Engineering:  Embedded and Realtime Systems,  Embedded Linux
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
Anything free is worth what you pay for it.

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

* [U-Boot-Users] test variable existence in hush
  2005-08-22 12:21 ` Wolfgang Denk
@ 2005-08-22 13:01   ` Andreas Engel
  0 siblings, 0 replies; 3+ messages in thread
From: Andreas Engel @ 2005-08-22 13:01 UTC (permalink / raw)
  To: u-boot

On Mon, 22 Aug 2005 14:21:58 +0200 Wolfgang Denk wrote:

>I cannot confirm this. The only part of hush which is  involved  here
>is the && processing which works fine for me..
>
>"test" is NOT a hush builtin.

I hit the send button too early...

Yes, "test" is not a hush builtin, but it is only available if the hush
parser is enabled.

>Sure:
>
>TRAB # foo=
>TRAB # test -n "$foo" && echo yes
>TRAB # test -n "$foo" || echo no
>no
>TRAB # test "$foo" && echo yes
>TRAB # test "$foo" || echo no
>no
>TRAB # foo=dummy
>TRAB # test -n "$foo" && echo yes
>yes
>TRAB # test -n "$foo" || echo no
>TRAB # test "$foo" && echo yes
>TRAB # test "$foo" || echo no
>no
>
>THe only problem I see is with "test -z":
>
>	TRAB # foo=
>	TRAB # test -z "$foo" && echo yes
>	TRAB # test -z "$foo" || echo no
>	no
>but
>	TRAB # test -z "" && echo yes
>	yes
>	TRAB # test -z "" || echo no
>	TRAB # 

No, I think this is misleading. A quick debugging session showed that
the problem is not the "test" command itself. With 'test -z ""' and
'test -n ""', the command will correctly see three arguments. However,
with 'test -n "$foo"' and 'test -z "$foo"' (and empty $foo), the command
will only get two arguments which always results in a return value of 1.
That's why 'test -n' seems to work.

Regards,
  Andreas Engel

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

end of thread, other threads:[~2005-08-22 13:01 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-08-22 10:57 [U-Boot-Users] test variable existence in hush Andreas Engel
2005-08-22 12:21 ` Wolfgang Denk
2005-08-22 13:01   ` Andreas Engel

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