bug-bash
[Top][All Lists]
Advanced

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

Re: readonly inconsistency with arrays


From: Zachary Santer
Subject: Re: readonly inconsistency with arrays
Date: Mon, 3 Jun 2024 18:57:10 -0400

On Mon, Jun 3, 2024 at 6:16 PM Will Allan via Bug reports for the GNU
Bourne Again SHell <bug-bash@gnu.org> wrote:
>
> init_vars () {  readonly string="foo"  readonly int=100  readonly array=(1 2)

My understanding is that the readonly builtin isn't supposed to handle
compound assignment syntax like the declare and local builtins
do.[1][2] That it might try to anyway is likely unintended.

Your best bet is to do:
  array=(1 2)
  readonly array
instead of trying to combine the two. This should give you the
behavior you expect.

[1]: 
https://www.gnu.org/software/bash/manual/html_node/Bourne-Shell-Builtins.html#index-readonly
[2]: https://www.gnu.org/software/bash/manual/html_node/Arrays.html



reply via email to

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