【发布时间】:2012-04-01 07:48:03
【问题描述】:
我有一个 config.txt 文件,其中的 IP 地址是这样的
10.10.10.1:80
10.10.10.13:8080
10.10.10.11:443
10.10.10.12:80
我想 ping 该文件中的每个 ip 地址
#!/bin/bash
file=config.txt
for line in `cat $file`
do
##this line is not correct, should strip :port and store to ip var
ip=$line|cut -d\: -f1
ping $ip
done
我是初学者,很抱歉这样的问题,但我自己找不到。
【问题讨论】:
-
for line in cat file将运行两次...一次使用line=cat,一次使用line=file。我不认为那是你想要的。
标签: bash variables loops ping cut