[PATCH 1/3] cmd: test: allow using [ as alias for test
Quentin Schulz
quentin.schulz at cherry.de
Wed Mar 11 14:08:33 CET 2026
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 <ravi at prevas.dk>
> ---
> 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
More information about the U-Boot
mailing list