0
我想使用重定向(学习目的),并想知道如何我可以引用这个数组,所以我可以遍历它。我知道还有其他方法,但我试图坚持重定向。在bash /重定向到一个循环引用数组
#!/bin/bash
count=0
for i in 10.10.{0..255}.{0..255}
do
ips[$count]=$i
let count+=1
done
echo -e "$count = count\n" #test code for amount
#problem code: trying to feed the array to the while loop via redirection
while read $element; do
echo -en "$element\n"
done < ${ips[@]}
感谢您的澄清。这是有道理的,而不是遍历数组来获得计数。关于引用的另外一个问题,你能解释一下这个语句里发生了什么(总分解),比如$(something)究竟做了什么? hashsign的引用是什么?谢谢。 '$ {#ips [@]}' – genx1mx6 2014-11-05 01:22:32
散列符号获取数组中的项目数。 '$ {ips [@]}'是地址列表,'$ {#ips [@]}'是计数。 – 2014-11-05 01:58:50