[U-Boot] [PATCH] cmd_itest.c: also support environment variables as arguments

Signed-off-by: Frans Meulenbroeks fransmeulenbroeks@gmail.com --- common/cmd_itest.c | 8 ++++++++ 1 files changed, 8 insertions(+), 0 deletions(-)
diff --git a/common/cmd_itest.c b/common/cmd_itest.c index 58c5e7b..78a4082 100644 --- a/common/cmd_itest.c +++ b/common/cmd_itest.c @@ -69,6 +69,10 @@ static long evalexp(char *s, int w) long l = 0; long *p;
+ /* if the parameter starts with a $ replace it with the environment value */ + if (s[0] == '$') { + s = getenv(&s[1]); + } /* if the parameter starts with a * then assume is a pointer to the value we want */ if (s[0] == '*') { p = (long *)simple_strtoul(&s[1], NULL, 16); @@ -86,6 +90,10 @@ static long evalexp(char *s, int w)
static char * evalstr(char *s) { + /* if the parameter starts with a $ replace it with the environment value */ + if (s[0] == '$') { + s = getenv(&s[1]); + } /* if the parameter starts with a * then assume a string pointer else its a literal */ if (s[0] == '*') { return (char *)simple_strtoul(&s[1], NULL, 16);

Hi Frans,
Signed-off-by: Frans Meulenbroeks fransmeulenbroeks@gmail.com
common/cmd_itest.c | 8 ++++++++ 1 files changed, 8 insertions(+), 0 deletions(-)
diff --git a/common/cmd_itest.c b/common/cmd_itest.c index 58c5e7b..78a4082 100644 --- a/common/cmd_itest.c +++ b/common/cmd_itest.c @@ -69,6 +69,10 @@ static long evalexp(char *s, int w) long l = 0; long *p;
- /* if the parameter starts with a $ replace it with the environment value */
- if (s[0] == '$') {
s = getenv(&s[1]);
- }
This is actually a good idea, but I believe this does not work for the preferred ${variable} syntax, right?
Cheers Detlev

Dear Detlev Zundel,
In message m2d3zstby2.fsf@ohwell.denx.de you wrote:
Hi Frans,
Signed-off-by: Frans Meulenbroeks fransmeulenbroeks@gmail.com
common/cmd_itest.c | 8 ++++++++ 1 files changed, 8 insertions(+), 0 deletions(-)
diff --git a/common/cmd_itest.c b/common/cmd_itest.c index 58c5e7b..78a4082 100644 --- a/common/cmd_itest.c +++ b/common/cmd_itest.c @@ -69,6 +69,10 @@ static long evalexp(char *s, int w) long l = 0; long *p;
- /* if the parameter starts with a $ replace it with the environment value */
- if (s[0] == '$') {
s = getenv(&s[1]);
- }
This is actually a good idea, but I believe this does not work for the preferred ${variable} syntax, right?
... not to mention that it's fundamentally broken if the variable in question is not an environment variable, but aplain hush shell variable.
If you want variable subsitution, then please let the shell do this. Don't reinvent the wheel.
Best regards,
Wolfgang Denk
participants (3)
-
Detlev Zundel
-
Frans Meulenbroeks
-
Wolfgang Denk