Hey, after another discussion with Grisha, and following one of his remarks, I kindly request your opinion on the attached patch (like: bad, not needed, already done, weak as it stands, harmful, etc.). It addresses the exporting of identifiers with have nameref attribute set. at the moment we have:
#a=10; declare -nx ra=a; bash -c 'echo "a:$a, ra:$ra, ra_excl:${!ra}."' a:, ra:a, ra_excl:. #a=10; declare -n ra=a; export ra; bash -c 'echo "a:$a, ra:$ra, ra_excl:${!ra}."' a:10, ra:a, ra_excl:10 so either you get reference value exported (not very useful, and probably not the intent when typing declare -nx reference=variable;), or you get the referenced variable exported, which is not necessarily expected, together with the variable with the reference value. The patch makes both of them work the same, and resolving the reference at export: bash-4.4$ a=10; declare -nx ra=a; bash -c 'echo "a:$a, ra:$ra, ra_excl:${!ra}."' a:, ra:10, ra_excl:. bash-4.4$ a=10; declare -n ra=a; export ra; bash -c 'echo "a:$a, ra:$ra, ra_excl:${!ra}."' a:, ra:10, ra_excl:. and also introduces a way to recover the current behaviour with the exporting of the target variable: bash-4.4$ a=10; declare -n ra=a; export -r ra; bash -c 'echo "a:$a, ra:$ra, ra_excl:${!ra}."' a:10, ra:10, ra_excl:. there are of course other possibilities to consider, but I agree with Grisha, that it is worthy of at least taking a look. cheers, pg
follow_references_on_export.patch
Description: Binary data