为什么第二条命令输出的不是a b c三行?
改进:
这里把ssh的标准输入关闭了,结果就正常了,可见,原来不能输出三行是有ssh的标准输入导致的
再次验证如下:
这里比较清晰地说明了b、c被ssh给读走了
如果不想费这心思,完全可以别走管道:
有时候就是这样,能用简单明了的写法,最好别摆酷
非图片版:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
[root@ceph-test-1 my-cluster]# echo -e "a\nb\nc" | while read c; do ssh localhost echo $c; done a [root@ceph-test-1 my-cluster]# echo -e "a\nb\nc" | while read c; do ssh localhost echo $c <&-; done a b c [root@ceph-test-1 my-cluster]# echo -e "a\nb\nc" | while read c; do ssh localhost 'while read c; do echo ">>$c";done'; done >>b >>c [root@ceph-test-1 my-cluster]# echo -e "a\nb\nc" | while read c; do ssh localhost 'while read d; do echo ">>$d";done'; echo ">$c";done >>b >>c >a [root@ceph-test-1 my-cluster]# for c in $(echo -e "a\nb\nc"); do ssh localhost echo $c; done a b c |