Re: inconsistency with "readonly" and scope

2012-04-15 Thread Linda Walsh
Andreas Schwab wrote: Maarten Billemont writes: On 15 Apr 2012, at 03:21, Chet Ramey wrote: If I declare a variable readonly at global scope, I wouldn't expect it to be overridden by some local namespace pollution. I think that's fine; in the local context, your variable has a different m

Re: inconsistency with "readonly" and scope

2012-04-15 Thread Andreas Schwab
Maarten Billemont writes: > On 15 Apr 2012, at 03:21, Chet Ramey wrote: >> >> If I declare a variable readonly at global scope, I wouldn't expect it >> to be overridden by some local namespace pollution. > > I think that's fine; in the local context, your variable has a > different meaning; it's

Re: inconsistency with "readonly" and scope

2012-04-15 Thread Maarten Billemont
On 15 Apr 2012, at 03:21, Chet Ramey wrote: > > If I declare a variable readonly at global scope, I wouldn't expect it > to be overridden by some local namespace pollution. I think that's fine; in the local context, your variable has a different meaning; it's another variable with the same name.

Re: inconsistency with "readonly" and scope

2012-04-14 Thread Chet Ramey
On 4/13/12 8:50 PM, Linda Walsh wrote: > > > Chet Ramey wrote: > >> This is intended. Bash doesn't allow a local copy of a variable to >> override a readonly global one. This can be a potential security hole, > > --- > You can look at it that way, but it also hinders modular programming. > >

Re: inconsistency with "readonly" and scope

2012-04-13 Thread Linda Walsh
Chet Ramey wrote: This is intended. Bash doesn't allow a local copy of a variable to override a readonly global one. This can be a potential security hole, --- You can look at it that way, but it also hinders modular programming. If I declare a variable to be local, I wouldn't expect it t

Re: inconsistency with "readonly" and scope

2012-04-12 Thread Chet Ramey
On 4/12/12 4:43 PM, dethrophes wrote: > have you tried local? > I'm not sure if it'll make a difference. It won't. > I don't agree that typeset/declare should be able to override/redefine a > readonly variable it would defeat the purpose in a way. I described the (hybrid/compromise) bash behavi

Re: inconsistency with "readonly" and scope

2012-04-12 Thread Chet Ramey
On 4/12/12 4:11 PM, Steven W. Orr wrote: > It took me a second to reproduce it, but here it is: > > -- > #! /bin/bash > > A() > { > typeset v1=Hello > > B > echo "IN B:$v1" > } > > B() > { > typeset -r v1=Goodbye > > : > } > typeset -r v1=abc > A > echo

Re: inconsistency with "readonly" and scope

2012-04-12 Thread dethrophes
Am 12.04.2012 22:38, schrieb Steven W. Orr: On 4/12/2012 4:21 PM, dethrophes wrote: Am 12.04.2012 22:11, schrieb Steven W. Orr: On 4/12/2012 2:16 PM, dethrophes wrote: Am 12.04.2012 14:27, schrieb Chet Ramey: On 4/11/12 4:12 PM, dethrophes wrote: I've also noticed weird behavior with "declar

Re: inconsistency with "readonly" and scope

2012-04-12 Thread Steven W. Orr
On 4/12/2012 4:21 PM, dethrophes wrote: Am 12.04.2012 22:11, schrieb Steven W. Orr: On 4/12/2012 2:16 PM, dethrophes wrote: Am 12.04.2012 14:27, schrieb Chet Ramey: On 4/11/12 4:12 PM, dethrophes wrote: I've also noticed weird behavior with "declare -gr" the r sometimes seems to override the

Re: inconsistency with "readonly" and scope

2012-04-12 Thread Chet Ramey
On 4/12/12 4:21 PM, dethrophes wrote: > I don't think it helps me but thanks for the try. > I would say zhats correct behavior. the code in the functions is only > executed when you call the functions. So the first executed readonly > variable is preserved. > Anyway my problem isn't with how reado

Re: inconsistency with "readonly" and scope

2012-04-12 Thread dethrophes
Am 12.04.2012 22:11, schrieb Steven W. Orr: On 4/12/2012 2:16 PM, dethrophes wrote: Am 12.04.2012 14:27, schrieb Chet Ramey: On 4/11/12 4:12 PM, dethrophes wrote: I've also noticed weird behavior with "declare -gr" the r sometimes seems to override the g, but not specific to functions It seem

Re: inconsistency with "readonly" and scope

2012-04-12 Thread Steven W. Orr
On 4/12/2012 2:16 PM, dethrophes wrote: Am 12.04.2012 14:27, schrieb Chet Ramey: On 4/11/12 4:12 PM, dethrophes wrote: I've also noticed weird behavior with "declare -gr" the r sometimes seems to override the g, but not specific to functions It seems to be specific either to the source file or

Re: inconsistency with "readonly" and scope

2012-04-12 Thread dethrophes
Am 12.04.2012 14:27, schrieb Chet Ramey: On 4/11/12 4:12 PM, dethrophes wrote: I've also noticed weird behavior with "declare -gr" the r sometimes seems to override the g, but not specific to functions It seems to be specific either to the source file or to the compound statement. I haven't bee

Re: inconsistency with "readonly" and scope

2012-04-12 Thread Chet Ramey
On 4/11/12 2:50 PM, Greg Wooledge wrote: > "declare" when used in a function acts like "local", and creates a variable > with scope local to that function. So does "declare -r". But "readonly", > which is otherwise the same as "declare -r", creates variables with global > scope. > > Is this inte

Re: inconsistency with "readonly" and scope

2012-04-12 Thread Chet Ramey
On 4/11/12 4:12 PM, dethrophes wrote: > I've also noticed weird behavior with "declare -gr" the r sometimes seems > to override the g, but not specific to functions It seems to be specific > either to the source file or to the compound statement. I haven't been able > to figure out exactly whats g

Re: inconsistency with "readonly" and scope

2012-04-11 Thread dethrophes
Am 11.04.2012 20:50, schrieb Greg Wooledge: "declare" when used in a function acts like "local", and creates a variable with scope local to that function. So does "declare -r". But "readonly", which is otherwise the same as "declare -r", creates variables with global scope. Is this intended?

inconsistency with "readonly" and scope

2012-04-11 Thread Greg Wooledge
"declare" when used in a function acts like "local", and creates a variable with scope local to that function. So does "declare -r". But "readonly", which is otherwise the same as "declare -r", creates variables with global scope. Is this intended? Tested with 2.05b, 3.something, and 4.2.20.