From: Rasmus Villemoes <ravi@prevas.dk>
To: u-boot@lists.denx.de
Cc: Francis Laniel <francis.laniel@amarulasolutions.com>,
Harald Seiler <hws@denx.de>, Tom Rini <trini@konsulko.com>
Subject: command negation in modern hush parser
Date: Wed, 11 Mar 2026 13:01:19 +0100 [thread overview]
Message-ID: <878qbyr2wg.fsf@prevas.dk> (raw)
Hi
Today, I was bitten by u-boot shell not supporting the negating
operator, as in
if ! some_command args ... ; then ... ; fi
So at first I thought about implementing a simple '!' command which,
similar to the the 'time' command, would just run the rest of the
arguments, but then negate the return code.
But then I looked at the modern hush parser code, which did seem to have
support for that in the shell itself. At least the "! command ..." gets
parsed, and there is code for rejecting "! ! command" which does seem to
be active, but unfortunately, the "! command" form doesn't actually work
as expected:
=> cli set modern
=> ! false
=> echo $?
1
=> ! true
=> echo $?
0
=> if ! false ; then echo "This should be printed" ; fi
=> if ! true ; then echo "This should _not_ be printed" ; fi
This should _not_ be printed
=> if ! echo "echoing always succeeds, so... " ; then echo "this should _not_ be printed" ; fi
echoing always succeeds, so...
this should _not_ be printed
=> version
U-Boot 2026.04-rc3-00079-gb008b86fd180-dirty (Mar 11 2026 - 12:44:08 +0100)
gcc (GCC) 15.2.1 20260209
GNU ld (GNU Binutils) 2.46
I don't really grok the whole parser code, but just injecting a simple
printf at the start of done_pipe, it seems that that gets called twice
for each command, and the flag indicating inversion gets reset on the
first call, after which it doesn't affect the actual return code of the
command:
=> ! echo hi
done_pipe entered, followup 0, ctx->inverted = 1
done_pipe entered, followup 0, ctx->inverted = 0
hi
Any ideas?
Rasmus
next reply other threads:[~2026-03-11 12:01 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-11 12:01 Rasmus Villemoes [this message]
2026-03-12 6:42 ` command negation in modern hush parser Anshul Dalal
2026-03-16 8:22 ` Rasmus Villemoes
2026-03-16 9:25 ` Anshul Dalal
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=878qbyr2wg.fsf@prevas.dk \
--to=ravi@prevas.dk \
--cc=francis.laniel@amarulasolutions.com \
--cc=hws@denx.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