Skip to contentSkip to conversation

cmd_itest.c: also support environment variables as arguments

PATCH New Frans Meulenbroeks 3 participants 3 messages Feb 25, 2010 – Feb 26, 2010

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 cmd_itest.c: also support environment variables as arguments

---
 common/cmd_itest.c |    8 ++++++++
 1 files changed, 8 insertions(+), 0 deletions(-)
common/cmd_itest.c +8 -0
index 58c5e7b..78a4082 100644
@@ -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);
Signature · 1 line
1.5.4.3
#1 lore raw

PATCH 1/1 cmd_itest.c: also support environment variables as arguments

Hi Frans,

Quoted 10 lines
---
 common/cmd_itest.c |    8 ++++++++
 1 files changed, 8 insertions(+), 0 deletions(-)
common/cmd_itest.c +0 -0
index 58c5e7b..78a4082 100644

common/cmd_itest.c static long evalexp(char *s, int w) · line 75

Quoted 7 lines
common/cmd_itest.c +4 -0
@@ -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

Signature · 8 lines
The management question  ...  is not  _whether_  to build a pilot system
and throw it away.  You _will_ do that.  The only question is whether to
plan  in advance  to build  a throwaway,  or  to promise  to deliver the
throwaway to customers.          - Fred Brooks, "The Mythical Man Month"
--
DENX Software Engineering GmbH,      MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich,  Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-40 Fax: (+49)-8142-66989-80 Email: dzu at denx.de
#2 lore raw

PATCH 1/1 cmd_itest.c: also support environment variables as arguments

Dear Detlev Zundel,

Quoted 15 lines · In message <[email protected]> you wrote:

Hi Frans,

Quoted 13 lines
---
 common/cmd_itest.c |    8 ++++++++
 1 files changed, 8 insertions(+), 0 deletions(-)
common/cmd_itest.c +0 -0
index 58c5e7b..78a4082 100644
@@ -69,6 +69,10 @@ static long evalexp(char *s, int w)
 	long l = 0;
 	long *p;
 
Quoted 7 lines

common/cmd_itest.c static long evalexp(char *s, int w) · line 75

Quoted 4 lines
common/cmd_itest.c +4 -0
+	/* 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

Signature · 8 lines
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
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
Remember thee Ay, thou poor ghost while memory holds a seat  In  this
distracted  globe.  Remember  thee!  Yea, from the table of my memory
I'll wipe away all trivial fond  records,  All  saws  of  books,  all
forms,  all  pressures past, That youth and observation copied there.
Hamlet, I : v : 95 William Shakespeare