I have a program that runs and asks users certain questions. I want to automate it so that every question is responded to with No.
yes no | <command>
Where <command>
is the command you want to answer no
to.
(or yes n
if you actually need to just output an n
)
The yes
command, by default, outputs a continuous stream of y
, in order to answer yes to every prompt. But you can pass in any other string as the argument, in order for it to repeat that to every prompt.
As pointed out by "just somebody", yes
isn't actually standardized. While it's available on every system I've ever used (various BSDs, Mac OS X, Linux, Solaris, Cygwin), if you somehow manage to find one in which it doesn't, the following should work:
while true; do echo no; done | <command>
Or as a full-fledged shell script implementation of yes
, you can use the following:
#!/bin/sh if [ $# -ge 1 ] then while true; do echo "$1"; done else while true; do echo y; done fi
actually, it looks funny ...
$ yes no
manpages excerpt:
$ man yes
YES(1) BSD General Commands Manual YES(1)
NAME
yes -- be repetitively affirmative
SYNOPSIS
yes [expletive]
DESCRIPTION
yes outputs expletive, or, by default, ``y'', forever.
...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With