[PATCH] RFC: nvedit: support doing one (extra) expansion of the value in "env set"
Wolfgang Denk
wd at denx.de
Wed Feb 12 12:38:48 CET 2020
Dear Rasmus,
In message <c48f9de9-ad02-3b45-ae2e-50c3086d6a68 at prevas.dk> you wrote:
>
> > HUSH does not support arrays anyway...
>
> Of course not, but they can be emulated by having variables foo0, foo1,
> foo2 and programmatically accessing the variable foo$index, if only
> there's a way to do that... In a sense, my BOOT_A_LEFT/BOOT_B_LEFT is
> also just an array with keys "A" and "B".
Actually the port to U-Boot cripples HUSH in many more aspects.
I've always hoped someone would some day volunteer and (1)( update
HUSH to a more recent (and less buggy) version and address a few of
the missing parts, like Command Substitution, which would be really
handy in many cases - here as well.
> > Well, there _are_ other ways...
>
> Please do tell. How can I avoid code duplication and access a variable
> whose name I generate by string concatenation/variable interpolation?
> I.e., I don't want anything like "if test $slot = "A" ; then setenv
> result BOOT_A_LEFT ; elif test $slot = "B" ; then setenv result
> BOOT_B_LEFT ; fi", because that doesn't scale.
=> slot=A
=> setenv result BOOT_${slot}_LEFT
=> printenv result
result=BOOT_A_LEFT
=> setenv foo 'setenv result BOOT_${slot}_LEFT; printenv result'
=> slot=B
=> run foo
result=BOOT_B_LEFT
=> slot=X
=> run foo
result=BOOT_X_LEFT
What exactly is your question?
> env set -E result "\${BOOT_${x}_LEFT}"
>
> corresponds to
>
> eval "result=\${BOOT_${x}_LEFT}"
...and things become already very tricky here, as you can see from
the need of having "\$" and "$" mixed. Now assume you have more of
this in the embedded variables...
I consider this change a bad idea. Instead of adding such a
hack we should add what you really want...
Best regards,
Wolfgang Denk
--
DENX Software Engineering GmbH, Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
ATTENTION: Despite Any Other Listing of Product Contents Found Here-
on, the Consumer is Advised That, in Actuality, This Product Consists
Of 99.9999999999% Empty Space.
More information about the U-Boot
mailing list