日期:2014-05-16  浏览次数:20640 次

Linux 中 while read 的使用

在Linux的bash编程中,while read对于我们实现一些循环的控制,会起到很好的作用。

但是在使用ssh的时候,特别要注意一点【-n 这个参数】,刚开始没有注意,循环处理的时候总是

只读第一行,剩余的不处理,恶心了我好长时间~~~~~~~


Linux命令的写法很灵活

cat ${tmp}-task | while read taskhost taskscript taskfile
do
{
   ssh -n ${taskhost} ${taskscript} ${taskfile}
}
done

while read taskhost taskscript taskfile
do
{
   ssh -n ${taskhost} ${taskscript} ${taskfile}
}
done < cat ${tmp}-task

ssh内容其实也不少,也需要细致学习才行