The fastest and easiest way to determine an OS is using uname -s
. Upon executing that command, you can evaluate the value and determine the system kernel architecture. Not all of them can distinguish between 32-bit or 64-bit.
#!/bin/dash
case "$(uname -s)" in
Linux)
machine="Linux"
;;
Darwin)
machine="MacOS"
;;
CYGWIN*)
machine="Cygwin"
;;
MINGW32)
machine="MinGW"
arch="32-bit"
;;
MINGW64)
machine="MinGW"
arch="64-bit"
;;
Interix)
machine="Interix"
;;
MSYS*)
machine="Msys"
;;
MINGW32)
machine="MinGW"
arch="32-bit"
;;
GNU)
machine="Debian HURD"
;;
GNU/kfreeBSD)
machine="Debian kfreeBSD"
;;
FreeBSD)
machine="FreeBSD"
;;
NetBSD)
machine="NetBSD"
;;
DragonFly)
machine="DragonFlyBSD"
;;
Haiku)
machine="Haiku"
;;
NONSTOP_KERNEL)
machine="NonStop"
;;
QNX)
machine="QNX"
;;
ReliantUNIX-Y)
machine="ReliantUNIX"
;;
SINIX-Y)
machine="SINIX"
;;
OSF1)
machine="Tru64"
;;
ULTRIX)
machine="Ultrix"
;;
IRIX)
machine="Irix"
arch="32-bit"
;;
IRIX64)
machine="Irix"
arch="64-bit"
;;
MINIX)
machine="Minix"
;;
SunOS)
machine="Solaris"
;;
UWIN-W7)
machine="UWIN"
;;
IS/WB)
machine="OpenVMS"
;;
OS/390)
machine="z/OS USS"
;;
SCO_SV)
machine="OpenServer | System V"
;;
sn5176)
machine="Cray"
;;
UnixWare)
machine="UnixWare"
;;
AIX)
machine="IBM AIX"
;;
OS400)
machine="IBM i with QSH"
;;
HP-UX)
machine="HP-UX"
;;
*)
1>&2 echo "[ ERROR ] unknown operating system architecture."
exit 1
;;
esac
That's all about the recipe for determining operating system architecture.