Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Shouldn't readonly (-r) prevent type changes?



On Sat, Jul 25, 2026 at 6:11 PM Oliver Kiddle <opk@xxxxxxx> 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 <markjreed@xxxxxxxxx>


Messages sorted by: Reverse Date, Date, Thread, Author