diff options
author | Wolfgang Denk <wd@denx.de> | 2013-03-23 23:50:34 +0000 |
---|---|---|
committer | Tom Rini <trini@ti.com> | 2013-05-01 16:24:01 -0400 |
commit | 855f18ea0e6ff83ec9ed5af74e82bc4bff30867d (patch) | |
tree | 2f1e664ce52eafdf3f3099437d4825fb8b774549 /include/configs/pxa-common.h | |
parent | 103c94b10481cf8479c9d0356e5202bc9200a04f (diff) | |
download | u-boot-imx-855f18ea0e6ff83ec9ed5af74e82bc4bff30867d.zip u-boot-imx-855f18ea0e6ff83ec9ed5af74e82bc4bff30867d.tar.gz u-boot-imx-855f18ea0e6ff83ec9ed5af74e82bc4bff30867d.tar.bz2 |
setexpr: add regex substring matching and substitution
Add "setexpr name gsub r s [t]" and "setexpr name sub r s [t]"
commands which implement substring matching for the regular
expression <r> in the string <t>, and substitution of the string <s>.
The result is assigned to the environment variable <name>. If <t> is
not supplied, the previous value of <name> is used instead. "gsub"
performs global substitution, while "sub" will replace only the first
substring.
Both commands are closely modeled after the gawk functions with the
same names.
Examples:
- Generate broadcast address by substituting the last two numbers of
the IP address by "255.255":
=> print ipaddr
ipaddr=192.168.1.104
=> setexpr broadcast sub "(.*\\.).*\\..*" "\\1255.255" $ipaddr
broadcast=192.168.255.255
- Depending on keyboard configuration (German vs. US keyboard) a
barcode scanner may initialize the MAC address as C0:E5:4E:02:06:DC
or as C0>E5>4E>02>06>DC. Make sure we always have a correct value:
=> print ethaddr
ethaddr=C0>E5>4E>02>06>DC
=> setexpr ethaddr gsub > :
ethaddr=C0:E5:4E:02:06:DC
- Do the same, but substitute one step at a time in a loop until no
futher matches:
=> setenv ethaddr C0>E5>4E>02>06>DC
=> while setexpr ethaddr sub > :
> do
> echo -----
> done
ethaddr=C0:E5>4E>02>06>DC
-----
ethaddr=C0:E5:4E>02>06>DC
-----
ethaddr=C0:E5:4E:02>06>DC
-----
ethaddr=C0:E5:4E:02:06>DC
-----
ethaddr=C0:E5:4E:02:06:DC
-----
C0:E5:4E:02:06:DC: No match
=> print ethaddr
ethaddr=C0:E5:4E:02:06:DC
etc.
To enable this feature, the CONFIG_REGEX option has to be defined in
the board config file.
Signed-off-by: Wolfgang Denk <wd@denx.de>
Diffstat (limited to 'include/configs/pxa-common.h')
0 files changed, 0 insertions, 0 deletions