如何使用#!/bin/sh(POSIX sh)按名称查找变量? [英] How can I look up a variable by name with #!/bin/sh (POSIX sh)?
本文介绍了如何使用#!/bin/sh(POSIX sh)按名称查找变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
f1="filename1";
i=1;
c=f$i
echo $c
我应该使用哪个shell命令,以便echo $c
返回"filename1"作为输出?
What shell command should I use so that echo $c
returns "filename1" as the output?
推荐答案
您可以使用eval
嵌套"变量替换.
You can use eval
to "nest" variable substitutions.
f1="filename1";
i=1;
eval c=\${f$i}
echo $c
这篇关于如何使用#!/bin/sh(POSIX sh)按名称查找变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文