linux – Installing packages if they don’t exist in Bash

This simply installs chosen packages if they’re not present on a Linux system using the apt package manager. Notes on improvements from any aspect are welcome!

setup_env.sh

#!/usr/bin/env bash
set -euo pipefail

install_if_not_exist() {
  if dpkg -s "$1" &>/dev/null; then
    PKG_EXIST=$(dpkg -s "$1" | grep "install ok installed")
    if ( -z "$PKG_EXIST" ); then
      sudo apt install "$1" -y
    fi
  else
    sudo apt install "$1" -y
  fi
}

sudo apt update -y

install_if_not_exist aria2
install_if_not_exist coreutils
install_if_not_exist gawk
install_if_not_exist jq
install_if_not_exist moreutils
install_if_not_exist sed