Input from within shell script

前端 未结 4 1056
[愿得一人]
[愿得一人] 2020-12-01 18:44

I have a script that calls an application that requires user input, e.g. run app that requires user to type in \'Y\' or \'N\'.
How can I get the shell script not to ask

4条回答
  •  盖世英雄少女心
    2020-12-01 19:32

    If the app reads from stdin (as opposed to from /dev/tty, as e.g. the passwd program does), then multiline input is the perfect candidate for a here-document.

    #!/bin/sh
    
    the_app [app options here] <

    As you can see, here-documents even allow parameter substitution. If you don't want this, use <<'EOF'.

提交回复
热议问题