[U-Boot-Users] test variable existence in hush

Wolfgang Denk wd at denx.de
Mon Aug 22 14:21:58 CEST 2005


In message <20050822125758.00001da8 at 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.




More information about the U-Boot mailing list