help-bash
[Top][All Lists]
Advanced

[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: Maroloccio
Subject: Re: name of a global variable to store the result of a function
Date: Sun, 24 May 2020 16:16:43 -0300
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:68.0) Gecko/20100101 Thunderbird/68.8.0

It's probably not "useless", as it does have a "use".
It's not "ineffectual", per se.

It's likely "sub-optimal", as a more robust alternative exists.

I think this use of the word "useless" is in the tradition of:
"useless use of cat", which is akin in meaning to "unnecessary" or "probably best replaced with an alternative".


On 24/05/2020 15:08, Pier Paolo Grassi wrote:
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





reply via email to

[Prev in Thread] Current Thread [Next in Thread]