From: Rasmus Villemoes <ravi@prevas.dk>
To: u-boot@lists.denx.de
Cc: Tom Rini <trini@konsulko.com>,
Quentin Schulz <quentin.schulz@cherry.de>,
Rasmus Villemoes <ravi@prevas.dk>
Subject: [PATCH v2 1/4] cmd: test: allow using [ as alias for test
Date: Thu, 12 Mar 2026 11:01:03 +0100 [thread overview]
Message-ID: <20260312100106.702368-2-ravi@prevas.dk> (raw)
In-Reply-To: <20260312100106.702368-1-ravi@prevas.dk>
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>
---
cmd/test.c | 19 +++++++++++++++++++
1 file changed, 19 insertions(+)
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[])
{
--
2.53.0
next prev parent reply other threads:[~2026-03-12 10:01 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-12 10:01 [PATCH v2 0/4] add [ as alias for test, fix 0/1 argument handling Rasmus Villemoes
2026-03-12 10:01 ` Rasmus Villemoes [this message]
2026-03-12 10:01 ` [PATCH v2 2/4] doc: test: document [ ] spelling of test Rasmus Villemoes
2026-03-12 10:01 ` [PATCH v2 3/4] test: add tests for left-bracket alias for 'test' command Rasmus Villemoes
2026-03-12 10:01 ` [PATCH v2 4/4] cmd: test: fix handling of single-argument form of test Rasmus Villemoes
2026-03-13 6:24 ` [PATCH v2 0/4] add [ as alias for test, fix 0/1 argument handling Anshul Dalal
2026-03-25 23:05 ` Tom Rini
2026-03-27 15:48 ` Franz Schnyder
2026-03-27 19:38 ` Rasmus Villemoes
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260312100106.702368-2-ravi@prevas.dk \
--to=ravi@prevas.dk \
--cc=quentin.schulz@cherry.de \
--cc=trini@konsulko.com \
--cc=u-boot@lists.denx.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox