Vor
Vor

Reputation: 35099

How to answer yes in Bash Script

Have a quick question,

imagine that I have this code:

mkdir -p $INSTALLDIR
sudo apt-get install -y git clojure leiningen
git clone git://github.com/maltoe/storm-install.git
./storm-install/storm_install.sh all `hostname` $INSTALLDIR

And this script will ask, do you want to install additional packages, and I want to say yes, How to do this automatically?

Or may be there is a way to kinda answer yes to any question by default?

Upvotes: 20

Views: 37665

Answers (6)

SSS
SSS

Reputation: 57

( echo yes ; echo no; echo yes ) | script.sh

Upvotes: 4

Jimmy
Jimmy

Reputation: 2280

If you are running a script, try this:

yes "yes" | bash script.sh 

Upvotes: 20

user5068816
user5068816

Reputation: 151

I not sure but i advice try:

echo yes | ./storm-install/storm_install.sh all `hostname` $INSTALLDIR

Upvotes: 15

Slava Semushin
Slava Semushin

Reputation: 15194

apt has also --force-yes option which may be helpful:

   --force-yes
       Force yes; This is a dangerous option that will cause apt to
       continue without prompting if it is doing something potentially
       harmful. It should not be used except in very special situations.
       Using force-yes can potentially destroy your system! Configuration
       Item: APT::Get::force-yes.

Upvotes: 3

jim mcnamara
jim mcnamara

Reputation: 16379

assume storm asks the question - use a here document - example:

mkdir -p $INSTALLDIR
sudo apt-get install -y git clojure leiningen
git clone git://github.com/maltoe/storm-install.git
./storm-install/storm_install.sh all `hostname` $INSTALLDIR  <<-EOF
yes
EOF

The EOF can be any nonsense characters the shell will not interpret.

Upvotes: 6

troelskn
troelskn

Reputation: 117417

With the command appropriately named yes

Upvotes: 10

Related Questions