I have the following Bash script:
func_1() {
local arg="$1"
local var="$(curl $someUrl "$arg")"
echo "$var"
}
main() {
# ...
# some_arg defined
output="$(func_1 "$some_arg")"
echo "$output"
}
main
However, after running this script, instead of getting the result of func_1 being assigned to output and then printed, the func_1 is being executed when echoed.
What do I have to modify to execute the function, assign the result and then use the variable in later part of the script?
output="$(func_1 "$some_arg")"tooutput=$(func_1 "$some_arg"). Your quotes are all messed up. They do not nest.echo "$( echo "date;date" )"vsecho "$( echo date;date )".output="$(func_1 "$some_arg" 2>&1)". What output is beeing outputted fromfunc_1?func_1is not being executed? I put in someechodirecting output to/dev/stderr, and it all executed as written.