[PATCH 1/3] cmd: test: allow using [ as alias for test
Rasmus Villemoes
ravi at prevas.dk
Wed Mar 11 14:25:28 CET 2026
On Wed, Mar 11 2026, Quentin Schulz <quentin.schulz at cherry.de> wrote:
> 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.
Ah, yes, thanks. Rather amazing that I could complete forget having
written that only 10 months ago...
Will update.
> Another question is if you have thought about/tested multi-expressions?
>
> e.g.
>
> [ aaa = aaa -a bbb = bbb ]
>
> and possibly also
>
> [ ! aaa = aaa ]
>
Yes, I did think about those, and I can certainly copy-paste a few more
test cases and spell them using [], but as the implementation is so
simple (check last argv, decrement argc) I couldn't really imagine those
being any different than the simple cases.
> I think adding tests for those would be nice too?
Sure, will do.
Rasmus
More information about the U-Boot
mailing list