当while read line 遇到 ssh
在实际工作中,有时会利用while + ssh 远程到多个server执行命令的需求,但是写shell时发现,脚本只能执行一次循环
1 | !/bin/sh |
原因: read 从stdin读取数据,’<’ 将文件重定向到stdin。而不幸的是,脚本试图运行的命令(ssh)也读取stdin,因此它最终会吃掉文件的其余部分。
解决方案
1 | !/bin/sh |
在实际工作中,有时会利用while + ssh 远程到多个server执行命令的需求,但是写shell时发现,脚本只能执行一次循环
1 | #!/bin/sh |
原因: read 从stdin读取数据,’<’ 将文件重定向到stdin。而不幸的是,脚本试图运行的命令(ssh)也读取stdin,因此它最终会吃掉文件的其余部分。
解决方案
1 | #!/bin/sh |