首页 > 解决方案 > Bash Shell While inside for loop not working-只选择第一个值

问题描述

我在 for 循环中运行一个简单的 while 循环,下面是我的代码。我的问题是在运行此代码时,while 循环仅从文件 iplist.txt 中选择第一行。

需要了解为什么我的 while 循环没有为整个文件逐行运行。

for node in `nodeset -e @nishant1`;

do
while read -r q; do

nslookup $q | grep uhc |awk '{print $4}' >/tmp/nslookup.txt

dest=`cat /tmp/nslookup.txt`

clush -w $node "sh /opt/OV/qa-ira/ira/bin/ira setProbe ICMP -on BDPassS -op icmpEcho -ta $q -tn ICMP_'$node'_'$dest' -tt IPv4 -ds 256"


done< /iplist.txt

done

标签: linuxbashshellfor-loopwhile-loop

解决方案


该命令很可能clush也从中读取,stdin因此它消耗了文件中的所有其他行。所以试试这样:

#
# prevent clush from reading current stdin
#
clush -w $node ... < /dev/null

推荐阅读