Shell script while read line loop stops after the first line

后端 未结 4 782
遇见更好的自我
遇见更好的自我 2020-11-21 23:52

I have the following shell script. The purpose is to loop thru each line of the target file (whose path is the input parameter to the script) and do work against each line.

4条回答
  •  悲哀的现实
    2020-11-22 00:44

    The problem is that do_work.sh runs ssh commands and by default ssh reads from stdin which is your input file. As a result, you only see the first line processed, because ssh consumes the rest of the file and your while loop terminates.

    To prevent this, pass the -n option to your ssh command to make it read from /dev/null instead of stdin.

提交回复
热议问题