Skip to content

Instantly share code, notes, and snippets.

@peter279k
Last active April 24, 2020 09:02
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save peter279k/cc738446699f1015b9a70ef031420a9d to your computer and use it in GitHub Desktop.
Save peter279k/cc738446699f1015b9a70ef031420a9d to your computer and use it in GitHub Desktop.
Find OS released dist name
#!/bin/bash
# Now it's available for Debian, Ubuntu, RedHat, CentOS and Fedora.
folder_root='/etc/'
dist_name='Unknown OS dist name'
release_paths=$(ls $folder_root 2>/dev/null | grep '\-release')
for release_path in $release_paths;
do
dist=$(cat ${folder_root}${release_path} | grep 'DISTRIB_DESCRIPTION=')
if [ $? != 1 ]; then
dist_name=$(echo $dist | sed -e 's/DISTRIB_DESCRIPTION=//g' | sed -e 's/"//g')
break;
fi;
dist=$(cat ${folder_root}${release_path} | grep 'PRETTY_NAME=')
if [ $? != 1 ]; then
dist_name=$(echo $dist | sed -e 's/PRETTY_NAME=//g' | sed -e 's/"//g')
break;
fi;
done;
echo $dist_name
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment