【发布时间】:2017-04-05 09:49:52
【问题描述】:
我有数组:
declare -A server
server[172.16.170.1]='t1.com'
server[172.16.170.2]='t2.com'
server[172.16.170.3]='t3.com'
server[172.16.170.4]='t4.com'
server[172.16.170.5]='t5.com'
.....
我不想每次都写,“t1,com,t2.com ...” 我想增加它 好的:
first=0
first=$(($first+1))
它适用于第一个元素。
first=0
first=$(($first+1))
declare -A server
server[172.16.170.1]='t$first.com'
server[172.16.170.2]='t$first.com'
server[172.16.170.3]='t$first.com'
server[172.16.170.4]='t$first.com'
server[172.16.170.5]='t$first.com'
.....
在输出中我们将有:
server[172.16.170.1]=t1.com
server[172.16.170.2]=t1.com
server[172.16.170.3]=t1.com
server[172.16.170.4]=t1.com
server[172.16.170.5]=t1.com
.....
我知道,我们应该使用循环,但是如果我有很多服务器,我应该如何使用循环“for”?使用我所有的数组变量?
【问题讨论】:
标签: arrays bash shell for-loop foreach