From: Wolfgang Denk Date: Wed, 12 Feb 2020 12:38:48 +0100 Subject: [PATCH] RFC: nvedit: support doing one (extra) expansion of the value in "env set" In-Reply-To: References: <20200205010812.20373-1-rasmus.villemoes@prevas.dk> <20200211163055.30A262403FE@gemini.denx.de> Message-ID: <20200212113848.997CB240057@gemini.denx.de> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de Dear Rasmus, In message 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.