[PATCH 01/11] cmd: test: add support for =~ operator

Tom Rini trini at konsulko.com
Tue May 6 18:52:21 CEST 2025


On Tue, May 06, 2025 at 10:49:31AM -0600, Tom Rini wrote:
> On Tue, May 06, 2025 at 04:10:25PM +0200, Rasmus Villemoes wrote:
> 
> > Currently, the only way to make use of regex matching in the shell is
> > by using "setexpr [g]sub" command. That's rather awkward for asking
> > whether a string matches a regex. At the very least, it requires
> > providing setexpr with a dummy target variable, but also, the return
> > value of setexpr doesn't say whether any substitutions were done, so
> > one would have to do some roundabout thing like
> > 
> >   env set dummy "${string_to_test}"
> >   setexpr sub dummy '<some regex>' ''
> >   if test "${dummy}" != "${string_to_test}" ; then ...
> > 
> > When CONFIG_REGEX is set, teach the test command a new operator, =~,
> > which will allow one to more naturally write
> > 
> >   if test "${string_to_test}" =~ '<some regex>' ; then ...
> > 
> > Signed-off-by: Rasmus Villemoes <ravi at prevas.dk>
> 
> We should also mention here (and then in docs) that this the same as the
> =~ operator in bash, which I only learned about now as part of answering
> my own question of "Are people going to expect =~ to do something
> else?".
> 
> With that,
> 
> Reviewed-by: Tom Rini <trini at konsulko.com>

Oh, and we should update doc/usage/cmd/setexpr.rst at least and we
should have one for test as well, but don't, yet.

-- 
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 659 bytes
Desc: not available
URL: <https://lists.denx.de/pipermail/u-boot/attachments/20250506/c19fefed/attachment.sig>


More information about the U-Boot mailing list