Vor Vor - 5 months ago 34
Linux Question

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?

Answer

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.

Comments