Supporting Multiple Distros in Scripts
At home I am a Slackware user. At work I support Debian and CentOS systems. Often when I write shell scripts I need to distinguish which distro I am running. I use a simple conditional logic test.
if [ -r "/etc/os-release" ]; then RELEASE_FILE="/etc/os-release" elif [ -r "/etc/system-release" ]; then RELEASE_FILE="/etc/system-release" elif [ -r "/etc/debian_version" ]; then RELEASE_FILE="/etc/debian_version" elif [ -r "/etc/centos-release" ]; then RELEASE_FILE="/etc/centos-release" elif [ -r "/etc/redhat-release" ]; then RELEASE_FILE="/etc/redhat-release" elif [ -r "/etc/slackware-version" ]; then RELEASE_FILE="/etc/slackware-version" fi
From there I can test the contents of the $RELEASE_FILE variables to know in which operating system the script is running.
Posted: Usability Tagged: General
Category:Next: Automating Computer Tasks
Previous: Display Managers