Sample Header Ad - 728x90

Creating a bash script to install packages

4 votes
2 answers
12698 views
I'm quite a newbie when it comes to bash. I'm trying to create a script that checks whether a package is installed or not. If not it will install that package. Not sure what I'm doing tbh.
#! /bin/bash
echo Installing/Checking packages from list

declare -a PKGS=("libreoffice", "firefox", "virtualbox", "vlc")
    
PKG_OK=$(dpkg-i -W --showformat='${Status}\n' PKGS |grep "install ok installed")


for i in "${PKGS[@]}"
do
	if [ "" = "$PKG_OK" ]; then
  		echo "No $PKGS, installing the package now"
  		sudo apt install $PKGS[@]
 	fi
done
Asked by Scriptkid_bash (49 rep)
Sep 16, 2022, 02:31 AM
Last activity: Dec 28, 2022, 04:19 PM