bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

discrepancy with variable assignments and simple commands between sh and


From: Mike Frysinger
Subject: discrepancy with variable assignments and simple commands between sh and bash
Date: Wed, 25 Aug 2010 00:33:47 -0400
User-agent: KMail/1.13.1 (Linux/2.6.35.2; KDE/4.4.5; x86_64; ; )

i'm finding that the `var=val cmd` syntax isnt working the same between `sh` 
and `bash` when the simple command is a function.  this is bash-4.1_p7, but 
testing some older ones seems to behave the same.  i'm not sure if this is "by 
design" or a bug ... 

simple example:
$ cat test.sh
unset a
a=a
echo e1 a=$a
a=b env | grep ^a=
echo e2 a=$a
f() { echo a=$a; }
a=c f
echo e3 a=$a

when run with `bash`, i get:
e1 a=a
a=b
e2 a=a
a=c
e3 a=a

however, when i execute with `sh` (a symlink to bash), i get:
e1 a=a
a=b
e2 a=a
a=c
e3 a=c

the difference here being the value in variable "a" after function "f" 
finishes executing.  i was expecting the behavior of `bash`, not of `sh`.  i 
cant seem to find anything covering this in the man page except for perhaps 
interpreting the meaning of some sections to mean this behavior is allowed.  
but i certainly didnt locate anything that would imply behavior of this would 
differ across bash and sh ...
-mike

Attachment: signature.asc
Description: This is a digitally signed message part.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]