1

It appears that pdksh and mksh has the scoping implementation I expected.

For example:

readonly x='global'

f() {
  local x
  readonly x='f'
  echo $x
}

g() {
  local x
  readonly x='g'
  echo $x
}

echo $x

f 
g

echo $x

pdksh and mksh produce my expected result:

global
f
g
global

And Bash fails:

line 5: local: x: readonly variable

Dash and Ksh93 failed my expect, too. (I've changed local to typeset in Ksh93's test.)

This seems confusing.

UPDATE: I've edited the question. The question before is not stated in a clear way.

weakish
  • 28,682
  • 5
  • 48
  • 60

1 Answers1

1

Bash and Dash don't fail if the global variable is not read only.

Korn (ksh93) doesn't fail only if none of the instances of x are read only.

Dennis Williamson
  • 346,391
  • 90
  • 374
  • 439
  • 1
    There's a [recent discussion](http://lists.gnu.org/archive/html/bug-bash/2011-02/msg00105.html) of this topic on the gnu.bash.bug mailing list. – Dennis Williamson Feb 18 '11 at 21:59