Is there a possible way to initialize a global variable in bash and assign it a value in a function, then use it out side the function scope?
Function example:
globla_var=""
_DBINFO()
{
curl -su $AUTH https://<balla bla >/databases | jq -c 'map(select(.plan.name != "Sandbox")) | .[] | {id, name}'| \
while read db
do
idb=$(echo "$db" | jq -r '.id')
name=$(echo "$db" | jq -r '.name')
if [[ $name = '<bla>' ]]; then
$global_var_her = $(<bla value>)
fi
done
}
then use it outside the function:
echo $global_var
the result
$0: line 16: =<bla bla>: command not found
I tried using declare:
declare -r global_var
same results
localordeclarebuiltins.globla_varwhich should beglobal_varas I believe._DBINFO()uses$global_var_her, not$global_varnor$globla_var.