How do I script a “yes” response for installing programs?

后端 未结 6 1693
面向向阳花
面向向阳花 2020-12-02 06:15

I work with Amazon Linux instances and I have a couple scripts to populate data and install all the programs I work with, but a couple of the programs ask:

D         


        
6条回答
  •  北荒
    北荒 (楼主)
    2020-12-02 06:45

    You might not have the ability to install Expect on the target server. This is often the case when one writes, say, a Jenkins job.

    If so, I would consider something like the answer to the following on askubuntu.com:

    https://askubuntu.com/questions/338857/automatically-enter-input-in-command-line

    printf 'y\nyes\nno\nmaybe\n' | ./script_that_needs_user_input
    

    Note that in some rare cases the command does not require the user to press enter after the character. in that case leave the newlines out:

    printf 'yyy' | ./script_that_needs_user_input
    

    For sake of completeness you can also use a here document:

    ./script_that_needs_user_input << EOF
    y
    y
    y
    EOF
    

    Or if your shell supports it a here string:

    ./script <<< "y
    y
    y
    "
    

    Or you can create a file with one input per line:

    ./script < inputfile
    

    Again, all credit for this answer goes to the author of the answer on askubuntu.com, lesmana.

提交回复
热议问题