[U-Boot] strange behaviors with setexpr syntax error and '==' != '-eq"

Wolfgang Denk wd at denx.de
Tue Sep 26 14:39:34 UTC 2017


Dear Clément Péron,

In message <CAJiuCcfNUtBYnHbs+9WGg00gLskVOQBi6EHk9aJ1+iL5OnJJsg at mail.gmail.com> you wrote:
> 
> I write a script on u-boot but i found 2 strange behaviors.

I'm tempted to rephrase: you made some errors :-)

> The first one is when I try to do a mask from a memory address and
> store it to an env variable.
> 
> => setexpr toto *{loadaddr} & 0xFF
> syntax error
> => setexpr toto *{loadaddr} & 0x3F
> syntax error
> => setexpr toto  0x3F & *{loadaddr}
> syntax error

This has nothing to dowith the setexpr command - the error message
comes from the shell.  It will issue the same error for other uses
of an (unmasked) ampersand:

->  echo a & echo b
syntax error


Note: you must always escape special characters.

Also, you probably want to write ${loadaddr} (mind the dollar
character).

So try:

	setexpr toto *${loadaddr} '&' 0xFF

> The second one is the difference between '==' and '-eq'
> 
> => setenv a 1
> => setenv b 2
> => if test ${a} -eq ${b}; then echo toto; fi;
> => if test ${a} == ${b}; then echo toto; fi;
> toto
> 
> Which doesn't seem logic.

Well, did you read the man page for the test command?

== is operating on STRING arguments, while -eq is operating on
INTEGER arguments.  So depending on the content of your variables
the result may be the same or different.



Best regards,

Wolfgang Denk

-- 
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
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
COBOL is for morons.                                 -- E.W. Dijkstra


More information about the U-Boot mailing list