Here's something which takes a different twist on /etc/os-release
, which has a standardized format based around setting shell variables, meaning you can source
it and use them. First have a look at the actual file to get the idea, then consider:
#!/bin/bash
source /etc/os-release
case $VERSION_ID in
"7")
echo "Raspbian 7 is wheezy."
;;
"8")
echo "Raspbian 8 is jessie."
;;
"9")
echo "Raspbian 9 is stretch."
;;
*)
echo "This is $NAME, not Raspbian."
;;
esac
It doesn't include anything about the kernel for which parsing uname -r
(or /proc/version
) is more appropriate. Also, it could be made more robust by actually checking $NAME
to make sure this isn't some other Debian/Raspbian derived distro using the same version numbering (although what you are doing will likely work with them anyway as they are parallel, which is why there's a Debian 6 but no Raspbian 6).
BTW stay away from Raspbian 9, it is still considered "testing".