[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
signature.asc
Description: OpenPGP digital signature
- name of a global variable to store the result of a function, Peng Yu, 2020/05/23
- Re: name of a global variable to store the result of a function, João Eiras, 2020/05/24
- Re: name of a global variable to store the result of a function,
Eli Schwartz <=
- Re: name of a global variable to store the result of a function, Pier Paolo Grassi, 2020/05/24
- Re: name of a global variable to store the result of a function, Eli Schwartz, 2020/05/24
- Re: name of a global variable to store the result of a function, Greg Wooledge, 2020/05/26
- Re: name of a global variable to store the result of a function, Peng Yu, 2020/05/26
- Re: name of a global variable to store the result of a function, Maroloccio, 2020/05/24