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: Eli Schwartz
Subject: Re: name of a global variable to store the result of a function
Date: Sun, 24 May 2020 13:50:40 -0400
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.8.0

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

Attachment: signature.asc
Description: OpenPGP digital signature


reply via email to

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