I need to make script that behaves differently per system. Today it is possible to run bash even on microsoft windows, mac, linux, hp-ux, solaris etc...
How can I determine which of these operating systems I am on? I don't need exact version, I just need to know if I am on windows, linux, solaris...
There is a standard shell command "uname" which returns the current platform as a string
To use this in a shell program a typical stanza might be
#!/bin/sh
if [ `uname` = "Linux" ] ;
then
echo "we are on the operating system of Linux"
fi
if [ `uname` = "FreeBSD" ] ;
then
echo "we are on the operating system of FreeBSD"
fi
More specific information is available but unfortunately it varies according to platform. On many versions of Linux ( and ISTR, Solaris ) there is a /etc/issue file which has the version name and number for the distribution installed. So on ubuntu
if [ -e "/etc/issue" ] ;
then
issue=`cat /etc/issue`
set -- $issue
if [ $1 = "Ubuntu" ] ;
then
echo "we are on Ubuntu version " $2
fi
fi
This will give version information
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With