How do I always answer No to any prompt with a bash script?
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.
...
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
for systems with no such command, just a simple echo should work
echo "no" | command
for repetitions , not that hard to make a while/for loop that goes on forever.