How do I make something like:

if (system name == Jessie)
if (system name == Wheezy)
echo "It won't work on your Raspberry Pi version, please update"

if (kernel version == >= 4.4)
if (kernel version == <= 4.4)
echo "Bad kernel version"

2 Answers 2


You can try something like this. You may have to enhance this but the below script will work for you syntactically and also will tell which files to lookup and verify.


debian_version=`egrep "jessie|wheezy" /etc/os-release`
if [ `echo $debian_version|grep -c "jessie"` == 1 ]
   echo "jesse"
elif [ `echo $debian_version|grep -c "wheezy"` == 1 ] 
   echo "wheezy"
   echo "Some other version"

kernel_version=`uname -a|awk '{print $3}'`
if [ $kernel_version == "4.4" ]
    echo "version is 4.4"
  • If your shebang is specifically bash (and not sh, since this is a bashism and not standard shell speak), you can use if [[ "$debian_version" =~ "jessie" ]] instead of that echo -> grep pipeline. Note the double brackets. Won't it be wheezy, BTW?
    – goldilocks
    Aug 30, 2016 at 12:41
  • @goldilocks . That's cool. I have used matching with the operator '~' when I used to write scripts in awk. I never knew this could be used like this in shell scripts. Can you please go ahead and correct. Always the best option should be in posts is what I believe.
    – Varad A G
    Aug 30, 2016 at 12:45
  • 2
    I corrected the "wheeze" to "wheezy" since I'm pretty sure that's wrong. The other bit I'll leave up to the reader; seeing multiple ways of doing something doesn't hurt and yours is safer if someone is doing this with !#/bin/sh (bash will behave differently when invoked as sh, and on Raspbian sh is actually linked to dash, not bash).
    – goldilocks
    Aug 30, 2016 at 12:49
  • What -eq in $kernel_version -eq "4.4" means?
    – user52089
    Aug 30, 2016 at 16:58
  • @k073l In shell script while comparing integers you need to use -eq, -ne -gt. and "==" is used for comparing strings.
    – Varad A G
    Aug 30, 2016 at 17:02

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:


source /etc/os-release

case $VERSION_ID in
    echo "Raspbian 7 is wheezy."
    echo "Raspbian 8 is jessie."
    echo "Raspbian 9 is stretch."
    echo "This is $NAME, not Raspbian."

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".

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.