
Dear Artem,
In message CAKaHn9+yL3naiDqbsQJWQ0Po=g=TmjjcPSKxkx5C4ay1M1AsUA@mail.gmail.com you wrote:
next examples just demonstrate how its works for already defined env variables which contain other variables (like storred env variables)
Which next examples?
Usage examples (from commit message):
=> setenv a hello; setenv b world; setenv c '${a} ${b}' => setenv -r d '${c}! ${a}...' => printenv d d=hello world! hello...
This is a very simple example, and I showed you how you can solve this one by just omitting the apostrophes:
=> setenv a hello; setenv b world; setenv c ${a} ${b} => setenv d ${c}! ${a}... => printenv d d=hello world! hello...
I _think_ what you actually have in mind is something like this:
=> setenv a hello => setenv b world => setenv c '${a} ${b}' => setenv a goodbye => setenv b sunshine
something to set d to: '${c}! ${a}...'
=> printenv d
Here my simple approach does not show what you want to have:
=> setenv a hello => setenv b world => setenv c ${a} ${b} => setenv a goodbye => setenv b sunshine => setenv d ${c}! ${a}... => printenv d d=hello world! goodbye...
That's because here evaluation takes place at assignment, but you want it when used - but being recursive here is neither a good idea nor standard.
How would you do it in a standard posix shell? You would have to use "eval", like that:
$ a=hello $ b=world $ c='${a} ${b}' $ a=goodbye $ b=sunshine $ d=$(eval echo $c) $ echo $d goodbye sunshine
But please note that "eval" is _not_ recursive!!
$ a='$b' $ eval echo $c $b sunshine
And this is why I object against this patch.
Oh, and in U-Boot you could write this as:
=> setenv a hello => setenv b world => setenv c '${a} ${b}' => setenv a goodbye => setenv b sunshine => setenv foo "setenv d ${c}! ${a}..." => run foo => printenv d d=goodbye sunshine! goodbye...
And yes, here you have to be careful about using ' or " as there is no recursion like you might expect.
So yes, it would be nice if we had "eval" (which will ocme with the hush update), and no, "eval" does not recurse either.
Best regards,
Wolfgang Denk