Created
August 24, 2022 17:54
-
-
Save KekTuSx/55298671c3c1933baae327f95da9dad8 to your computer and use it in GitHub Desktop.
Checks which package manager to use.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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