Sysop: | Amessyroom |
---|---|
Location: | Fayetteville, NC |
Users: | 43 |
Nodes: | 6 (0 / 6) |
Uptime: | 108:32:10 |
Calls: | 290 |
Files: | 905 |
Messages: | 76,683 |
Consider these two command lines (run from a bash shell, but that's
actually not relevant):
$ bash -c 'foo=bar;myfun() { local foo; echo "In myfun(), foo = $foo"; };myfun'
In myfun(), foo =
$ dash -c 'foo=bar;myfun() { local foo; echo "In myfun(), foo = $foo"; };myfun'
In myfun(), foo = bar
$
The difference is that in dash, the local foo picks up the value of the global foo, while in bash, it is empty.
I'm not standards obsessed like some people in these newsgroups; I care
more about desirable functionality. In this case, I would not be surprised to hear that the dash behavior is more POSIX-ly correct, but it seems clear to me that the bash behavior is more desirable.
I frequently use "local" precisely to ensure that I get a fresh, un-initialized variable. Yes, I know that you can always do: local foo='' but that takes the fun out of it.
Consider these two command lines (run from a bash shell, but that's
actually not relevant):
$ bash -c 'foo=bar;myfun() { local foo; echo "In myfun(), foo = $foo"; };myfun'
In myfun(), foo =
$ dash -c 'foo=bar;myfun() { local foo; echo "In myfun(), foo = $foo"; };myfun'
In myfun(), foo = bar
$
The difference is that in dash, the local foo picks up the value of the global foo, while in bash, it is empty.
I'm not standards obsessed like some people in these newsgroups; I care
more about desirable functionality. In this case, I would not be surprised to hear that the dash behavior is more POSIX-ly correct, but it seems clear to me that the bash behavior is more desirable.
I frequently use "local" precisely to ensure that I get a fresh, un-initialized variable.
Yes, I know that you can always do: local foo=''
but that takes the fun out of it.
$ bash -c 'foo=bar;myfun() { local foo; echo "In myfun(), foo = $foo"; };myfun'
In myfun(), foo =
$ dash -c 'foo=bar;myfun() { local foo; echo "In myfun(), foo = $foo"; };myfun'
In myfun(), foo = bar
$
The difference is that in dash, the local foo picks up the value of the global foo, while in bash, it is empty.
I'm not standards obsessed like some people in these newsgroups; I care
more about desirable functionality. In this case, I would not be surprised to hear that the dash behavior is more POSIX-ly correct,
but it seems clear to me that the bash behavior is more
desirable.
I frequently use "local" precisely to ensure that I get a fresh, un-initialized variable.
foo=bar;myfun() { local foo; echo "In myfun(), foo = $foo"; };myfun
I'm not standards obsessed like some people in these newsgroups; I care
more about desirable functionality. In this case, I would not be surprised to hear that the dash behavior is more POSIX-ly correct,
Surprisingly, "local" isn't part of the POSIX shell language at all.
[...]
Is there any POSIX-y shell that does not implement "local"?