[英]how can I use a variable as a variable name in this bash script
I am currently trying to make a variable name that would consist of another variable我目前正在尝试创建一个包含另一个变量的变量名
while [ "$countf" -le 9 ]; do
vname=$( echo fcp"$countf" )
$vname=$( awk -F, -vs="\$fc$countf" '{for (i=1;i<=NF;i++)if($i~"^"s"$"){print i;exit;}}{print "not found"}' <<< $first_line )
countf=$(( countf + 1 ))
done
although when I go to execute the the script that includes the code, something along the lines of the following is outputted:尽管当我去执行包含代码的脚本时,会输出以下内容:
fcp1=not: command not found
fcp1 being the content of the vname variable. fcp1 是 vname 变量的内容。 I've tried several different solutions but have not gotten anything to work yet as of right now, if someone could point out what I am doing wrong though I would really appreciate it, thanks.我已经尝试了几种不同的解决方案,但到目前为止还没有任何工作,如果有人能指出我做错了什么,尽管我真的很感激,谢谢。
try this:尝试这个:
eval cat$p2="something"
without the quotes around the variable name.没有围绕变量名称的引号。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.