I want to detect the package manager on the system and then use that later on in my script. However, I feel this is clunky.
type apt    &> /dev/null && MANAGER=apt    && DISTRO="Debian/Ubuntu"
type yum    &> /dev/null && MANAGER=yum    && DISTRO="RHEL/Fedora/CentOS"
type dnf    &> /dev/null && MANAGER=dnf    && DISTRO="RHEL/Fedora/CentOS"   # $MANAGER=dnf will be default if both dnf and yum are present
type zypper &> /dev/null && MANAGER=zypper && DISTRO="SLES"
type apk    &> /dev/null && MANAGER=apk    && DISTRO="Alpine"
What I would like to do is define some kind of array or key-value pair such that
apt, Debian/Ubuntu
dnf, RedHat/Fedora/CentOS
and then have a function that allocates based on this pseudo-code:
for each item in the key-value pair {
    type {key} &> /dev/null && MANAGER={key} && DISTRO={value}
}
Can someone show me how that might be constructed in bash?
 
     
    