This still has the problem that if a user accidentally uses the same name as
the first
variable then the function fails (which is how I discovered this problem to
begin with).
$ newarr=(1 2 3 4)
$ testarr=(1 2 3 4)
$ copy_args a newarr
$ print ${a[@]}
$ copy_args a testarr
$ print ${a[@]}
1 2 3 4
Is there any way to make sure a user can't break this function without forcing
them to
not use certain variable names?
- Derek Newhall
----- Original Message -----
From: David Korn <[email protected]>
To: [email protected]; [email protected]
Cc:
Sent: Tuesday, March 6, 2012 8:57 AM
Subject: Re: Re: [ast-users] Is there a way to pass a variable number of
namerefs to a function?
cc: [email protected]
Subject: Re: Re: [ast-users] Is there a way to pass a variable number of
namerefs to a function?
--------
Here is a complete program that copies any number of source arrays into the
destination passing the array names as references.
function copy_args # dest src ...
{
nameref newarr=$1 arr
for arr in "$@"
do newarr+=(${arr[@]})
done
}
a=(x y z)
b=(a b c)
typeset -a c
copy_args c a b
typeset -p c
David Korn
[email protected]
_______________________________________________
ast-users mailing list
[email protected]
https://mailman.research.att.com/mailman/listinfo/ast-users
_______________________________________________
ast-users mailing list
[email protected]
https://mailman.research.att.com/mailman/listinfo/ast-users