scripting:bash:returnvar
Differences
This shows you the differences between two versions of the page.
| scripting:bash:returnvar [2015/01/28 12:13] – created warnaud | scripting:bash:returnvar [2020/12/17 05:23] (current) – external edit 127.0.0.1 | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| + | When you want to save values between functions of your bash script, there are several ways: | ||
| + | - Use the same variable name and don't create them as " | ||
| + | { | ||
| + | myresult=' | ||
| + | } | ||
| + | |||
| + | myfunc | ||
| + | echo $myresult</ | ||
| + | - Let you function handle arguments: <code bash> | ||
| + | { | ||
| + | local __resultvar=$1 | ||
| + | local myresult=' | ||
| + | eval $__resultvar="' | ||
| + | } | ||
| + | |||
| + | myfunc result | ||
| + | echo $result</ | ||
| + | |||
| + | Reference: [[http:// | ||
