Sujet : Re: About the "nameref" feature in bash...
De : gazelle (at) *nospam* shell.xmission.com (Kenny McCormack)
Groupes : comp.unix.shellDate : 09. Dec 2024, 14:57:55
Autres entêtes
Organisation : The official candy of the new Millennium
Message-ID : <vj6t13$1fsuf$1@news.xmission.com>
References : 1 2
User-Agent : trn 4.0-test77 (Sep 1, 2010)
In article <
vj48k5$3r1bq$1@dont-email.me>,
Janis Papanagnou <janis_papanagnou+
ng@hotmail.com> wrote:
...
This is all well and good, but it leaves open the question of "How do I
assign a value to the nameref itself, given that any reference to the
nameref gets converted to a reference to whatever the nameref points to?"
>
If used in functions - where the actual function parameter from the
call cannot be changed from within the function ex post - it makes
sense to not "overwrite" the calling parameter.
To clarify, my actual use case does not involve functions at all. That's
why, in my OP, I made it clear that "the docs" talk mostly in terms of
using it with functions - implying that that was not my use case.
My use case is in mainline code, where I need to load up a bunch of
shell variables from a database. Like this:
mapfile -t < <(sqlite3 ...)
idx=0
for MyNameRef in var1 var2 var3 ...
do MyNameRef="${MAPFILE[idx++]}"
done
It all works fine; it all works just like the docs say it would.
I just find it a little strange; that's all. There is another (non-Unix)
scripting language with which I am familiar, where they implemented
"pointers" late-in-development; they followed the C idiom more closely,
where an unadorned instance of the pointer variable refers to the pointer
itself and to dereference it, you stick a * in front. This may be a little
more verbose, but it makes more sense to me.
Anyway, it seems clear at this point that the only 2 ways to assign to the
pointer itself (in "mainline code") are as described in the OP. I'm OK
with that.
-- 1/20/17: A great day for all those people who are sick of being toldthey don't know how to spell "you're" (or "there").