[Top][All Lists]

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

Re: cannot declare local variables if they're readonly

From: Stephane Chazelas
Subject: Re: cannot declare local variables if they're readonly
Date: Thu, 23 Jul 2015 11:29:25 +0100
User-agent: Mutt/1.5.21 (2010-09-15)

2015-07-23 01:12:01 +0200, isabella parakiss:
> From variables.c
>                                        The test against old_var's context
>      level is to disallow local copies of readonly global variables (since I
>      believe that this could be a security hole).
> Can you please explain how that can be a security hole?
> $ readonly wtf; fn () { local wtf; }; fn
> bash: local: wtf: readonly variable
> You can't even be sure that you can set *local* variables in a function.
> This is a problem.
> Most of the shells that support local variables (ksh93, mksh, zsh, dash...)
> allow this.  The only one I could find that doesn't is busybox.

I agree with you. That was discussed on another list a few
months ago. Unfortunately Chet seems to be of a different


To be fair, you also need to consider cases like:

readonly c=299792458

light_year() {
  REPLY=$((c * 86400 * 365))

my_func() {
  local a=1 b=2 c=3
  light_year "$((a + b + c))"

What that means is that with this kind of dynamic scoping,
"readonly" is not very helpful. I don't remember ever using it.


reply via email to

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