Bash Yes to All

Bash Yes to All

Do you remember when Homer Simpson worked at home? Long did not enjoy it. Therefore he is represented by birds, which automatically screen by pressing the “y” key. How could this be done in BASH?

Yes command inserts the “y” character of STDIN infinitely times.

yes

You can use it in way of STDIN redirection to another command:

yes y | command

Let’s write a small script, that will expect three lines of text from you:

#!/bin/bash
read AAA
read BBB
read CCC
echo "$AAA, $BBB, $CCC"

Now, try to execute our script with yes in pipe:

yes | ./read.sh

If you want o give the opposite answer to our script, it is possible. Just pass string argument to yes:

yes n | ./read.sh

If script expects capital ‘Yes’ use:

yes Yes | ./read.sh

Some commands have an “assume-yes” flag ‘-y’, for example: yum, apt-get.

Leave a Comment