2014-10-30 53 views
0

我有以下行切如何抛出一个符合numberpairs随机量

FileName|1.0.0.0 2.0.0.0 3.0.0.4 4.0.1.2 #.... and so on 

我检查,如果该文件存在

if [ -f /srv/torrentfiles/$film.torrent ] 
then 

,现在我要为每一个数字对做某事像:

while there is a new NumberPair(1.0.0.0) 
do somthing with NumberPair 

但我该怎么做,因为我不知道会有多少数字对。 壳有可能吗?

回答

1

使用参数扩展来提取行的文件名,然后就遍历的数字:

#!/bin/bash 
line='FileName|1.0.0.0 2.0.0.0 3.0.0.4 4.0.1.2' 
filename=${line%|*} 
for pair in ${line#*|} ; do 
    echo "$filename" "$pair" 
done 
+1

看起来不错 - 也许有些双引号将是有益的? – 2014-10-30 15:03:45

+0

@TomFenech:已添加。 – choroba 2014-10-30 15:16:46