Hi Rasmus,
On 3/11/26 1:09 PM, Rasmus Villemoes wrote:
I often find myself writing something like
if [ "$somevar" = 123 ] ; then ...
only to realize that that syntax doesn't work in U-Boot shell, and
must be spelled
if test "$somevar" = 123 ; then
It only takes a few lines of code to support this POSIX-standardized
alias for test, and helps developers focus on their actual problems
instead of dealing with such unexpected quirks of the shell.
Signed-off-by: Rasmus Villemoes <[email protected]>
---
cmd/test.c | 19 +++++++++++++++++++
Please don't forget to update the docs. It still states "Unlike in
ordinary shells, it cannot be spelled [.", c.f.
https://docs.u-boot.org/en/latest/usage/cmd/test.html#description. The
synopsis should also have a few examples using the new syntax.
Another question is if you have thought about/tested multi-expressions?
e.g.
[ aaa = aaa -a bbb = bbb ]
and possibly also
[ ! aaa = aaa ]
which I'm assuming should be equivalent to [ aaa != aaa ] (of course
this test doesn't make much sense, but there seems to be support for the
-e operator for checking file existence). I think adding tests for those
would be nice too?
Cheers,
Quentin