I'm very new to bash and I'm trying to run script in python I have. When the script runs, the first thing it prompt is y/n question, and I would like to automate this part so I can run it automatically without this part.
Based on this post, I have tried to autofill it with the following script:
(.venv) reut@whatever:~/git/my_amazing_script$ echo -e "y\ny\ny\ny"; for year in $(seq 20
17 1 2020) ;do python3 ./my_nice_script.py -start_year $year -end_year $year ;done
>>>
y
y
y
y
Will process with the following parametersstart_year=2017, end_year=2017,
Please confirm [y/n].
As it can be seen, when it runs, it prints first all the y and then prompt again the y/n question.
I would like my script to run and autofill the y/n so I don't need to type and it can iterate. How can I do that?
yes
into it? – Toby Speight Oct 20 '22 at 15:31echo "y" | python3 ./my_nice_script.py -start_year $year -end_year $year
– aviro Oct 20 '22 at 15:35yes | python3 ...
– ilkkachu Oct 20 '22 at 15:39echo
before the Python script, without any redirections. It'll just print to the terminal, same as you ranecho hello
any other time. You're looking for the pipe operator|
. – ilkkachu Oct 20 '22 at 15:40yes
is for - read its man page. In your example, you would writeyes | python3 ./my_nice_script.py …
– Toby Speight Oct 20 '22 at 15:56echo … | for …
, notecho … ; for …
. Similarly withyes
you wantyes | …
, notyes ; …
. – Kamil Maciorowski Oct 20 '22 at 16:10