Skip to content

Instantly share code, notes, and snippets.

@KekTuSx
Created August 24, 2022 17:54
Show Gist options
  • Save KekTuSx/55298671c3c1933baae327f95da9dad8 to your computer and use it in GitHub Desktop.
Save KekTuSx/55298671c3c1933baae327f95da9dad8 to your computer and use it in GitHub Desktop.
Checks which package manager to use.
#!/bin/bash
declare -A pkgman
pgkman[apt]=$(which apt)
pkgman[yum]=$(which yum)
pkgman[pacman]=$(which pacman)
for i in "${!pkgman[@]}" # takes index of array
do
# apt (debian, ubuntu, mint...)
if which "${pgkman[$i]}"; then # checks if the value (output of which) is not null
if [ "$i" = apt ]; then
echo "This system is running apt."
fi
# rpm/yum (redhat, opensuse, fedora, centos...)
if [ "$i" = yum ]; then
echo "This system is running yum."
fi
# pacman (arch, manjaro...)
if [ "$i" = pacman ]; then
echo "This system is running pacman."
fi
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment