[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: name of a global variable to store the result of a function
From: |
Pier Paolo Grassi |
Subject: |
Re: name of a global variable to store the result of a function |
Date: |
Sun, 24 May 2020 20:08:05 +0200 |
why "useless"? what is wrong about using eval?
Il giorno dom 24 mag 2020 alle ore 19:51 Eli Schwartz <
address@hidden> ha scritto:
> On 5/24/20 1:39 PM, João Eiras wrote:
> > Use whatever variable name you want.
> > But if you want to make utility code that robust and does not depend on
> > magic variable names, you could pass the name of the output variable as a
> > parameter, e.g.:
> >
> > function do_stuff {
> > local varname="$1"
> > local result="somevalue"
> > eval "$varname=\"\$result\""
> > }
> >
> > myresult=
> > do_stuff myresult
> > echo r:$myresult
> Useless use of eval, consider printf -v or declare -g instead.
>
> --
> Eli Schwartz
> Arch Linux Bug Wrangler and Trusted User
>
>