报告在for循环中处理哪个元素

时间:2016-07-25 11:16:12

标签: unix for-loop

假设我有一个目录,其中包含一些子目录和一些文件,其中包含了我的gzip。

这是我使用的命令:

for DATA in 9372161117 9372161118 9372161119 9372161153 9372161162 9372161163 9372161174 9372161189 9372161202 9372953017 9372953023 9372953024 9372953041 9372953049 9372953050 9372953053 9372953060 9374339086 9374339107 9374339128 9374339140 9374344040 9374344041 9374344138 9374345027 9374363112 9374363116 9374363117 9374363139 9374364101 9374365025 9374365109 9374365129 9374365160 9374682068 9374682069 9374682130 9374683008 9374683019 9374683020 9374683043 9374683044 9374683045 ; do 
    echo "Processing *.idat-files in folder ${DATA}..."; 
    gzip -v ${DATA}/*.idat; 
    echo "========================"; 
    echo ""; 
done

我知道如何报告正在处理DATA列表中的哪个元素。但我的问题是:我能得到一个数字吗?因此,报告将类似于:"处理目录号1:9372161117","处理目录号2:9372161118"等

1 个答案:

答案 0 :(得分:1)

是的,你可以。将迭代编号保留在i然后打印&在每次迭代时递增它:

i=1;
for DATA in 9372161117 9372161118 9372161119 9372161153 9372161162 9372161163 9372161174 9372161189 9372161202 9372953017 9372953023 9372953024 9372953041 9372953049 9372953050 9372953053 9372953060 9374339086 9374339107 9374339128 9374339140 9374344040 9374344041 9374344138 9374345027 9374363112 9374363116 9374363117 9374363139 9374364101 9374365025 9374365109 9374365129 9374365160 9374682068 9374682069 9374682130 9374683008 9374683019 9374683020 9374683043 9374683044 9374683045 ; do 
    echo "Processing directory number ${i}: ${DATA} ";
    echo "Processing *.idat-files in folder ${DATA}..."; 
    gzip -v ${DATA}/*.idat; 
    echo "========================"; 
    echo ""; 
    ((i++));
done