Dear Wolfgang,

With your help, I have satisfied my need.

On 04/09/2014 11:52 PM, Wolfgang Denk wrote:
Dear James,

In message <5345d493.4080...@gmail.com> you wrote:

Heh.  As soon as you have to change _any_ code, you can as well
upgrade.

I was hoping (in vain perhaps) to do my work modifying only the environment.

Yes, I understand this.  But I have to admit that I don't see an easy
way.

Hm... thinking about it, you _can_ do this, but it's a bit ugly...

POC code:

        => print ethaddr ipaddr serverip
        ethaddr=00:10:ec:01:08:84
        ipaddr=192.168.100.6
        serverip=192.168.1.1

        => echo E=$foo_ethaddr I=$foo_ipaddr S=$foo_serverip
        E= I= S=

        => setenv setvar 'setenv tmp "foo_$arg=$$arg"'

        => for arg in ethaddr ipaddr serverip ; do
        > run setvar
        > run tmp
        > echo E=$foo_ethaddr I=$foo_ipaddr S=$foo_serverip
        > done
        E=00:10:ec:01:08:84 I= S=
        E=00:10:ec:01:08:84 I=192.168.100.6 S=
        E=00:10:ec:01:08:84 I=192.168.100.6 S=192.168.1.1

As you can see, I'm useing a two-step approach to first constuct a
command and then to run it.  This "consumes" 2 environment variables
("tmp" and "arg"), but this should be an acceptable price...

Extending this a bit further to include yet another env var, I have the following that allows a list to be saved and restored.

        => setenv setvar 'setenv tmp "v_$arg=$$arg"'
        => setenv usevar 'setenv t v_$arg;setenv tmp "setenv $arg $$t"'
        =>
And testing these:
        => setenv list "ipaddr ethaddr list"
        => printenv ipaddr ethaddr
        ipaddr=10.3.134.80
        ethaddr=00:00:17:88:09:36
        =>
        => # to save
        => for arg in $list; do run setvar; run tmp; done
        => showvar
        HUSH_VERSION=0.01
        arg=list
        v_ipaddr=10.3.134.80
        v_ethaddr=00:00:17:88:09:36
        v_list=ipaddr ethaddr list
        =>
        => # simulate "env default -f"
        => setenv ethaddr; setenv ipaddr; setenv list
        =>
        => # to restore (note use of v_list rather than list)
        => for arg in $v_list; do run usevar; run tmp; done
        => printenv ipaddr ethaddr list
        ipaddr=10.3.134.80
        ethaddr=00:00:17:88:09:36
        list=ipaddr ethaddr list
        =>

Perhaps this isn't as nice looking as it could be. But, it does solve the problem at hand, which has value for me. The solution boils down to two definitions in the default environment (setvar and usevar) and then a single script line to save the values and another single script line to restore them. I don't consider this addition burdensome at all.

And to paraphrase a former US Sec Def, "You code with the tools you have rather than with the tools you might like to have."

Setting temporaries to commands that are then executed as a means to getting evaluations done when needed seems like a great addition to the "bag of tricks"

...

The new env command allows for a lot of interesting features, ...

I look forward to using these new facilities.

And, I appreciate you help very much.

Best regards,
Jim
--
Jim Chargin
AJA Video Systems                       j...@aja.com
(530) 271-3334                          http://www.aja.com
_______________________________________________
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot

Reply via email to