Error with 'env var-name=value sh'

Error with 'env var-name=value sh'

Post by Dan Yos » Thu, 05 Apr 2001 00:36:23



Hello all,

Last week I posted about problems with dashes in shell variable names.
I'm still having to use an app that needs them, but I was encouraged by
several of you to use the "env" commmand: env my-var=myvalue myprog
[args] .  This works just great.  However, if "myprog" happens to be
"sh" or if myprog spawns sh somewhere in its execution, it errors out.

Example (myprog is a test C program):

bash$ env my-var=hello myprog
in myprog, getenv("my-var") is 'hello' .
bash$ env my-var=hello sh
my-var=hello is not an identifier.
bash$ env myvar=hello sh
sh$

So, if I take out the dash, sh executes, and I'm left at the sh prompt.
If there's a dash in the variable name, though, sh won't run.  So, my
main problem is that some of the "myprogs" out there will spawn shells
as part of their execution, and when they do those shells will fail.

One more note:
bash$ env my-var=hello bash
bash$

(If I spawn a bash and not sh, things are fine).

Yes, I have read the entire man pages for sh and env, but I haven't
found anything that helps me here.

Thanks very much,
Dan

 
 
 

1. pd-ksh/zsh won't inherit '747=jet' env var?

From a discussion in a non-Usenet group. Tested on a netbsd system.

$ env 747=jet /bin/sh -c "env |grep jet"
747=jet
$ env 747=jet /bin/csh -c "env |grep jet"
747=jet
$ env 747=jet /bin/tcsh -c "env |grep jet"
747=jet
$ env 747=jet /bin/ksh -c "env |grep jet"
$ env 747=jet /usr/local/bin/ksh93 -c "env |grep jet"
747=jet
$ env 747=jet /usr/local/bin/zsh -c "env |grep jet"  
$

Setting POSIXLY_CORRECT=1 didn't change /bin/ksh.

/bin/ksh             is PD KSH v5.2.14 99/07/13.2
/usr/local/bin/ksh93 is Version M 1993-12-28 n-
/usr/local/bin/zsh   is zsh 4.0.6 (i386-unknown-netbsdelf1.5.2)

What's going on here? Why is the variable that doesn't start
with a letter being squished?

Elijah
------
originally discussing csh's "setenv" not liking variable names like "747"

2. SSL for SMTP and POP3

3. Does sed '/'$var'/d' textfile work if $var has / in it???

4. Samsung ML-1710 Laser Print3er

5. Q:sh:Setting env by reading other files - like csh 'source'

6. Linux drivers for Diamond and Symbios

7. sh var -> awk var -> sh var

8. Token Ring

9. what does the env in "env name=value command" buy me?

10. Referencing an env var from an env var

11. replacing parameters' names with parameters' values

12. grep on '$VAR ' (read: $VAR with a SPACE " " after it)

13. that sun env var thing -- it's the old LD_LIBRARY_PATH thing right?