Skip to content

Instantly share code, notes, and snippets.

@59023g
Last active February 8, 2018 15:14
Show Gist options
  • Save 59023g/cb632616a7c39fcd0f9e11190617efbe to your computer and use it in GitHub Desktop.
Save 59023g/cb632616a7c39fcd0f9e11190617efbe to your computer and use it in GitHub Desktop.
bash: loop through package array, if not exist, install package ( non-interactive )
!#/bin/bash
apt-get update
packages=( "curl" "python2.7" "git", "make", "openjdk-8-jre" )
for i in "${packages[@]}"
do
if ! [ -x "$(command -v $i)" ]; then
echo "--- installing $i ---" > &1
apt-get -y install $i
else
echo "--- $i already installed --- "
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment