Switch from file contents to STDIN in piped command? (Linux Shell)

前端 未结 4 1459
南旧
南旧 2020-12-31 22:28

I have a program (that I did not write) which is not designed to read in commands from a file. Entering commands on STDIN is pretty tedious, so I\'d like to be able to autom

相关标签:
4条回答
  • 2020-12-31 23:09

    Same as Idelic answer with more simple syntax ;)

    cat your_file_with_commands - | sh your_script
    
    0 讨论(0)
  • 2020-12-31 23:22

    Have you tried using something like tail -f commandfile | command I think that should pipe the lines of the file to command without closing the file descriptor afterwards. Use -n to specify the number of lines to be piped if tail -f doesn't catch all of them.

    0 讨论(0)
  • 2020-12-31 23:27

    I would do something like

    (cat your_file_with_commands; cat) | sh your_script
    

    That way, when the file with commands is done, the second cat will feed your script with whatever you type on stdin afterwards.

    0 讨论(0)
  • 2020-12-31 23:31

    I would think expect would work for this.

    0 讨论(0)
提交回复
热议问题