Indirect variable assignment in bash
问题 Seems that the recommended way of doing indirect variable setting in bash is to use eval : var=x; val=foo eval $var=$val echo $x # --> foo The problem is the usual one with eval : var=x; val=1$\'\\n\'pwd eval $var=$val # bad output here (and since it is recommended in many places, I wonder just how many scripts are vulnerable because of this...) In any case, the obvious solution of using (escaped) quotes doesn\'t really work: var=x; val=1\\\"$\'\\n\'pwd\\\" eval $var=\\\"$val\\\" # fail with