Passing arguments to an interactive program non-interactively

前端 未结 6 1026
一生所求
一生所求 2020-11-22 05:06

I have a bash script that employs the read command to read arguments to commands interactively, for example yes/no options. Is there a way to call this script i

6条回答
  •  忘掉有多难
    2020-11-22 05:33

    You can put the data in a file and re-direct it like this:

    $ cat file.sh
    #!/bin/bash
    
    read x
    read y
    echo $x
    echo $y
    

    Data for the script:

    $ cat data.txt
    2
    3
    

    Executing the script:

    $ file.sh < data.txt
    2
    3
    

提交回复
热议问题