Bash String concatenation and get content

后端 未结 2 780
[愿得一人]
[愿得一人] 2021-01-28 23:28

I have a bash loop, I\'m trying to read the all variables:

var1=\"hello1\"

var2=\"hello2\"

var3=\"hello3\"

for i in `seq 1 3`;
do
 ab=var$i
 # Now ab == var1,         


        
2条回答
  •  悲哀的现实
    2021-01-29 00:22

    var1="hello1"
    var2="hello2"
    var3="hello3"
    
    for i in `seq 1 3`;
    do
        ab=var$i
        echo ${!ab}
    done
    

    I'm not sure it is the best solution to your larger problem, but it is the direct solution to your immediate request.

提交回复
热议问题