June 03, 2022    Share on: Twitter | Facebook | HackerNews | Reddit

Bash - determine if script runs on Linux, macOS or other system

unameOut="$(uname -s)"
case "${unameOut}" in
    Linux*)     machine=Linux;;
    Darwin*)    machine=Mac;;
    CYGWIN*)    machine=Cygwin;;
    MINGW*)     machine=MinGw;;
    *)          machine="UNKNOWN:${unameOut}"
echo ${machine}

Credits: The solution from bash - How to check if running in Cygwin, Mac or Linux? - Stack Overflow