dev += ops

Simple Robust OS Detection in Bash Using $OSTYPE

| Comments

I was using lazyweb to solve this problem. Google’s results had solutions where people were calling all sorts of commands and parsing different files to detect system types. I didn’t want to do a syscall. I wanted this solution to be as platform independant as possible. I only needed to know if it was linux/solaris/osx/bsd etc etc. ┬áNot version or somehting special. SImple enough. 1 minute of RTFM’n the bash manual turned up $OSTYPE and $HOSTTYPE

Man I love simple solutions!

P.S. First post!

P.P.S posterious’s syntax support sucks. took longer to figure out than this post did to write.

edit: converted to markdown used gist for code highlight