On 2013-04-03 11:00, Nikolai Kondrashov wrote: > >>>It doesn't work because you are trying to redefine an existing > >>>readonly variable. > >> > >>Yes, but I'm explicitly redefining it locally, only for this function. > >>And this works for variables previously defined in the calling function. > > > >You're not redefining it locally, you are unsuccessfully trying to override a > >global. > > How is this different? > > bash -c 'declare v=1; function a() { declare v=2; }; a; echo "$v"'
From `help declare': When used in a function, `declare' makes NAMEs local, as with the `local' command. The `-g' option suppresses this behavior. > >>This: > >> > >> bash -c 'a() { echo "$v"; }; b() { declare -r v=123; a; }; b' > >> > >>Produces this: > >> > >> 123 > > > >That is *inside* the function, not *outside* the function. > > I'd say that "v" is declared outside function "a", where it is accessed, or do > you mean that there is no concept of separate functions in Bash and all > "functions" are just one function? $v is not populated at initial runtime, it is populated when it is accessed. Chris
pgpJ99rQ_Absd.pgp
Description: PGP signature