diff options
| author | Rasmus Villemoes <ravi@prevas.dk> | 2026-03-12 11:01:03 +0100 |
|---|---|---|
| committer | Tom Rini <trini@konsulko.com> | 2026-03-25 14:37:55 -0600 |
| commit | fc8bf9a984c118d551b3f93c66f1ae2733b9b588 (patch) | |
| tree | d80c611b99126a6d35a37b99785a1b3e11deb1c6 /cmd | |
| parent | 12a9c83cba29b0acf3d41fb40de6416c473c0ba3 (diff) | |
| download | u-boot-fc8bf9a984c118d551b3f93c66f1ae2733b9b588.tar.gz u-boot-fc8bf9a984c118d551b3f93c66f1ae2733b9b588.zip | |
cmd: test: allow using [ as alias for test
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@prevas.dk>
Tested-by: Anshul Dalal <anshuld@ti.com>
Diffstat (limited to 'cmd')
| -rw-r--r-- | cmd/test.c | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/cmd/test.c b/cmd/test.c index a9ac07e6143..f0645ef98f1 100644 --- a/cmd/test.c +++ b/cmd/test.c @@ -63,6 +63,14 @@ static int do_test(struct cmd_tbl *cmdtp, int flag, int argc, char * const *ap; int i, op, left, adv, expr, last_expr, last_unop, last_binop; + if (!strcmp(argv[0], "[")) { + if (strcmp(argv[argc - 1], "]")) { + printf("[: missing terminating ]\n"); + return 1; + } + argc--; + } + /* args? */ if (argc < 3) return 1; @@ -212,6 +220,17 @@ U_BOOT_CMD( "[args..]" ); +/* + * This does not use the U_BOOT_CMD macro as [ can't be used in symbol names + */ +ll_entry_declare(struct cmd_tbl, lbracket, cmd) = { + "[", CONFIG_SYS_MAXARGS, cmd_always_repeatable, do_test, + "alias for 'test'", +#ifdef CONFIG_SYS_LONGHELP + " <test expression> ]" +#endif /* CONFIG_SYS_LONGHELP */ +}; + static int do_false(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) { |
