[PATCH v2 0/4] add [ as alias for test, fix 0/1 argument handling

Rasmus Villemoes ravi at prevas.dk
Fri Mar 27 20:38:12 CET 2026


On Fri, Mar 27 2026, Franz Schnyder <fra.schnyder at gmail.com> wrote:

> On Wed, Mar 25, 2026 at 05:05:59PM -0600, Tom Rini wrote:
>> On Thu, 12 Mar 2026 11:01:02 +0100, Rasmus Villemoes wrote:
>> 
>> > Make 'test' behave a little more like its cousins in other shells, by
>> > allowing the [ ... ] spelling, and while here, fix up the handling of
>> > a single, non-empty argument to comply with POSIX.
>> > 
>> > v2: update documentation, add a few more test cases.
>> > 
>> > CI is happy: https://github.com/u-boot/u-boot/pull/905
>> > 
>> > [...]
>> 
>> Applied to u-boot/next, thanks!
>> 
>> [1/4] cmd: test: allow using [ as alias for test
>>       commit: fc8bf9a984c118d551b3f93c66f1ae2733b9b588
>> [2/4] doc: test: document [ ] spelling of test
>>       commit: d44f61582947564991cce7501f2e5db0b29ebad6
>> [3/4] test: add tests for left-bracket alias for 'test' command
>>       commit: 6f9cc3310a764aaae4478b5a8a0c0cae3b2be4a1
>> [4/4] cmd: test: fix handling of single-argument form of test
>>       commit: 8b0619579b2282050e7fb0d92fbc645b79d18bae
>> -- 
>> Tom
>> 
>> 
> Hello,
>
> While preparing a patch series based on u-boot/next, I realised that 
> the bootflow on our module broke.
> I discovered that the issue was introduced with 
> commit 8b0619579b2 ("cmd: test: fix handling of single-argument form of test")
>
> This change breaks our boot script as it relies on the behaviour of test
> with unquoted empty expansions. For example:
>
> ```
> test -n ${m4boot} || env set m4boot ';'
> ```
> Is now `test -n`, as there are no quotation marks. It now returns 
> true, so the fallback assignment is skipped and it breaks our boot flow.
>
> Any ideas? I think that we will not be the only ones affected by 
> this once it's merged into master.

Urrgh, sorry about that. That snippet is arguably fragile and buggy, but
yes, similar code can exist elsewhere.

I don't really like it, but I suppose one could special-case the
single-argument case and interpret

  test -n

as

  test -n ""

with all other single-argument strings behaving as they do now. This
would need a separate test case and explicit documentation.  It's
probably quite rare that one would test a string for emptiness where a
possible non-empty value is exactly "-n", and since the single-argument
case hasn't really been supported in U-Boot until now, I don't think
such code really exists. Moreover, I don't think one should ever rely on
that single-argument behaviour anyway;

  test "$str"

should always be spelled

  test -n "$str"

Single-argument 'test -z' does not need special treatment, because
both 'test -z' and 'test -z ""' are true, but we could add the former as
a test case as well if we do implement the above.

Rasmus


More information about the U-Boot mailing list