Skip to content
Advertisement

Is there any way to auto-send a “no” response to a script?

For example, I have this script:

read -p "$(echo 'choose yes/no: ')" repl
case $repl in
    [Yy]* ) echo "yes";;
    [Nn]* ) echo "no";;
esac

I can run yes | bash script and the script will automatically output "yes"

I want to know if I can send a negative response to it and automatically output "no". Sorry if this has been asked before but I can’t find anything related.

Advertisement

Answer

yes repeatedly outputs a string that you give it as a command line argument. The default string (if invoked with no arguments) is y.

So it sounds like you want yes n | bash script

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement