是的,是的,我知道您可能会喜欢“嘿,还有成百上千的其他人在问同样的问题”,但这不是事实。我不是想做这样的事情:
foo="example1"
bar="example2"
foobar="$foo$bar"
我正在尝试这样做:
foo="example1"
$foo="examle2"
但是,每当我尝试这样做时,我都会收到一条错误消息,内容为:
bash: example1=example2: command not found
有什么建议?这有可能吗?
这里有些例子:
declare [-g] "${foo}=example2"
declare -n foo='example1'
foo='example2'
eval "${foo}=example2"
mapfile -t "${foo}" <<< 'example2'
printf -v "${foo}" '%s' 'example2'
IFS='' read -r "${foo}" <<< 'example2'
typeset [-g] "${foo}=example2"
就像其他用户所说的那样,在进行eval
间接分配时要格外小心。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句