Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: [PATCH] Fix crash on unset-through-nameref
On Wed, Mar 6, 2024 at 11:17 AM Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> wrote:
>
> assign() {
> typeset -g $1
> typeset -nu var=$1
> local value=$2
> var=$value
> }
Of course there's also no reason to write that specific function that
way. You can simply do
assign() {
unset $1
typeset -g $1=$2
}
The reason for using a named reference would be when you're going do
more things with $var and $value than just assign them, such as
calling another function, or when you want to do something like
append() {
typeset -nu var=$1
local value=$2
# Maybe do something else to $value ? Then:
var+=$value
}
Mostly because "typeset" doesn't understand += syntax.
Messages sorted by:
Reverse Date,
Date,
Thread,
Author