I have a code like this:
#!/usr/bin/env bash test_this(){ export ABC="ABC" echo "some output" } final_output="the otput is $(test_this)" echo "$ABC"
Unfortunately, the variable ABC not set.
I need to call test_this , like this, because in my real program I give it several arguments, it performs various complex operations that call various other functions that are on the way to export this or that (based on these arguments) and at the end some then the output string to return. A call twice, once to get the export, and once for the output string will be bad.
Question: what can I do to have both export and output string, but only with one call to such a function?
The answer I'm happy with (thanks to paxdiablo):
#!/usr/bin/env bash test_this(){ export ABC="ABC" export A_VERY_OBSCURE_NAME="some output" } test_this final_output="the otput is $A_VERY_OBSCURE_NAME" echo "$ABC"
function bash export echo
robert
source share