How to answer yes in Bash Script

You have a quick question,

imagine 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 if you want to install additional packages, and I want to say yes , How to do this automatically?

Or maybe there is a way to answer the yes question to any default question?

+6
source share
7 answers

Suppose the storm asks a question - use a document here - an 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 

EOFs can be any meaningless characters that the shell will not interpret.

+4
source

With the appropriate yes command

+5
source

I'm not sure, but I advise you to try:

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

If you are using a script, try the following:

 yes "yes" | bash script.sh 
+4
source

apt also has the --force-yes option, which may be useful:

  --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. 
+3
source

I have a script to pass โ€œyesโ€ a couple of times, and finally, we need to pass a โ€œversion numberโ€ to deploy to it. Any suggestions?

+2
source
 ( echo yes ; echo no; echo yes ) | script.sh 
0
source

Source: https://habr.com/ru/post/945292/


All Articles