Re: Shouldn't readonly (-r) prevent type changes?
"Mark J. Reed" <[email protected]> Sat, 25 Jul 2026 21:35:27 -0400
| Newsgroups | gmane.comp.shells.zsh.devel |
|---|---|
| Message-ID | <CAA=-s3ySiC7j0C=uk0oz8LUz1pR5PEQ7FuPnmLjvfin4-KH=PQ@mail.gmail.com> |
--0000000000007dcb420657799f95 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Sat, Jul 25, 2026 at 6:11=E2=80=AFPM Oliver Kiddle <[email protected]> wrote: > I think ksh treats all variables as being arrays so thatisn't a type > conversion. It was already a one element array. > That's equally true in bash and ksh - you can treat scalar parameters as 1-element arrays, and likewise treating an array as a scalar parameter will get you its first element. But that doesn't extend to the type flags; there's a visible difference between a var that has been explicitly declared as an array (either by assignment or typeset/declare) and one that hasn't. And it's not quite as a simple as ksh lets you change it and bash doesn't. I was able to get ksh to toggle the array type of a readonly parameter once, but I haven't been able to reproduce that result since. It doesn't raise an error, but the type is not changed. Whereas bash always raises an error. -- Mark J. Reed <[email protected]> --0000000000007dcb420657799f95 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable <div dir=3D"ltr"><div dir=3D"ltr"><span style=3D"background-color:transpare= nt">On Sat, Jul 25, 2026 at 6:11=E2=80=AFPM Oliver Kiddle <<a href=3D"ma= ilto:[email protected]">[email protected]</a>> wrote:</span></div><div class=3D"gmai= l_quote gmail_quote_container"><blockquote class=3D"gmail_quote" style=3D"m= argin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left= :1ex">I think ksh treats all variables as being arrays so thatisn't a t= ype<br> conversion. It was already a one element array.<br></blockquote><div><br></= div><div>That's equally true in bash and ksh - you can treat scalar par= ameters as 1-element arrays, and likewise treating an array as a scalar par= ameter=C2=A0will get you its first element. But that doesn't extend to = the type flags; there's a visible difference between a var that has bee= n explicitly declared as an array (either by assignment or typeset/declare)= and one that hasn't.=C2=A0</div><div><br></div><div>And it's not q= uite as a simple as ksh lets you change it and bash doesn't. I was able= to get ksh to toggle the array type of a readonly parameter once, but I ha= ven't been able to reproduce that result since. It doesn't raise an= error, but the type is not changed. Whereas bash always raises an error.</= div><div><br></div><div>--</div></div><div dir=3D"ltr" class=3D"gmail_signa= ture">Mark J. Reed <<a href=3D"mailto:[email protected]" target=3D"_bl= ank">[email protected]</a>><br></div></div> --0000000000007dcb420657799f95--