Shell script while read line loop stops after the first line

后端 未结 4 770
遇见更好的自我
遇见更好的自我 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:47

    ssh -n option prevents checking the exit status of ssh when using HEREdoc while piping output to another program. So use of /dev/null as stdin is preferred.

    #!/bin/bash
    while read ONELINE ; do
       ssh ubuntu@host_xyz &1 | filter_pgm 
       echo "Hi, $ONELINE. You come here often?"
       process_response_pgm 
    EOF
       if [ ${PIPESTATUS[0]} -ne 0 ] ; then
          echo "aborting loop"
          exit ${PIPESTATUS[0]}
       fi
    done << input_list.txt
    

提交回复
热议问题