Question: 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...

Answer: 
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
bash has a global var called `$OSTYPE`. Type echo `$OSTYPE` to see:

```
echo "$OSTYPE"
// linux-gnu

```

From the [bash man page](http://linux.die.net/man/1/bash):

> 
> OSTYPE Automatically set to a string that describes the operating system on which bash is executing. The default is system-dependent.
> 
> 
> 

---

An alternative is to use the [`uname`](http://linux.die.net/man/1/uname) command (without any arguments) or `uname -s` what it the same as `uname` defaults to `-s`.

Example on Linux

```
uname
// Linux

```