Automating an entry for terminal

前端 未结 3 1758
无人及你
无人及你 2021-01-23 19:19

I have a problem which do not really know how to ask. I will try to explain as best as possible.

I have to automate an installation process using a bash script. In the

3条回答
  •  别那么骄傲
    2021-01-23 20:00

    While a particularly difficult script might do some magic to explicitly read from the terminal rather than stdin, odds are you could just pipe to the script using bash pipeline syntax:

    echo yes | python configure.py
    

    or if you prefer, the "single command" version using bash here string syntax:

    python configure.py <<

    Lastly, if you need to provide multiple lines of input, probably the easiest approach is bash's heredoc syntax:

    # Remove the single quotes if you need to do variable interpolation in the
    # heredoc; the delimiter ENDOFINPUT is arbitrary, it just has to be used
    # (with or without single quotes) after the `<<` operator, and w/o quotes
    # at the end of the input to terminate the heredoc
    python configure.py <<'ENDOFINPUT'
    yes
    anotherresponse
    andyetanother
    ENDOFINPUT
    

提交回复
热议问题