Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Shell how to pass only some user input to script?

If I have a very simple shell script like this:

echo "thing 1?"
read input1
echo $input1

echo "thing 2?"
read input2
echo $input2

How can I call the script/command with only 1 of the user inputs provided, while allowing any subsequent reads calls to prompt my terminal? I have been doing printf "foo\n" | sh myscript.sh which does pass in the 1st read, but then when it get’s to the 2nd, instead of prompting the user the script just exits.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Use cat to read from standard input.

( echo foo; cat ) | sh myscript.sh
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading