Re: integer variable that unsets itself causes segfault
From:
Zachary Santer
Subject:
Re: integer variable that unsets itself causes segfault
Date:
Sun, 24 Aug 2025 10:47:14 -0400
On Sat, Aug 23, 2025 at 11:41 PM Martin D Kealey
<martin@kurahaupo.gen.nz> wrote:
>
> Ignoring -i when binding (only applying it when assigning) would seem like
> a reasonable backwards-compatible extension, but can anyone think of a
> circumstance where failing to leave the name unbound, and/or failing to
> return a non-zero exit status, could conceivably break something useful?
-i may as well work the same as -l, -u, and -r, when combined with -n.
What could the user expect to happen when -i and -n are combined?
Something they actually want? Why would they want that? If your answer
is to silently ignore -i and allow the declare command to succeed, the
user still isn't getting what they expect to happen, assuming they
expected something useful. An error message is more helpful.
>From the manual:
-n Give each name the nameref attribute, making it a name reference
to another variable. That other variable is defined by the value of
name. All references, assignments, and attribute modifications to
name, except those using or changing the -n attribute itself, are
performed on the variable referenced by name's value. The nameref
attribute cannot be applied to array variables.
I might have expected
$ declare -ni reference=variable
to have the same effect as
$ declare -n reference=variable
$ declare -i reference
That being:
$ declare -p reference variable
declare -n reference="variable"
declare -i variable
Not going to argue that the behavior should be changed to work like that.