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

Re: uninvited members of associative array



On Fri, Dec 16, 2022 at 06:13:45AM -0800, Ray Andrews wrote:
> not really a hard error, just some printout issue. I'll pursue
> that.

It's only "just a printout issue" because the quotes are missing
is a harmless debug print statement.  In different contexts this
can be disastrous.

Just make a habit to quote variables.  For arrays,

 "$@"
 "${array[@]}"
 "${(kv)array[@]}"
 "${(@kv)array}"

are safe.  The shell automatically quotes each word of the array
separately with "@" (but not with "*").  If you do not quote, you
have to keep track of all possible valus of a variable and
remember whether quoting is necessary or not every time you expand
variables.  In the wild, almost all scripts have bugs because of
missing quoting, e.g. script snippets inside Jenkins pipeline
definitions.

Ciao

Dominik ^_^  ^_^

--

Dominik Vogt




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