cc: [email protected]
Subject: Re: Re: Re: [ast-users] Is there a way to pass a variable number of
namerefs to a function?
--------
> $ 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 t
> hem to
> not use certain variable names?
>
>
> - Derek Newhall
>
You are correct that this is not working. I think that can be fixed
since the names came from $@.
However, the following is a work around that should work and will
only bind named to the caller.
===================cut here================================
function copy_args # dest src ...
{
nameref newarr=$1
shift
while [[ $1 ]]
do nameref arr=$1
newarr+=(${arr[@]})
typeset +n arr
shift
done
}
newarr=(1 2 3 4)
testarr=(1 2 3 4)
copy_args a newarr
print ${a[@]}
===================cut here================================
David Korn
[email protected]
_______________________________________________
ast-users mailing list
[email protected]
https://mailman.research.att.com/mailman/listinfo/ast-users