Skip to content

Instantly share code, notes, and snippets.

@durzo
Created November 24, 2016 12:11
Show Gist options
  • Save durzo/892c4f81b255c1f24daba92922224db0 to your computer and use it in GitHub Desktop.
Save durzo/892c4f81b255c1f24daba92922224db0 to your computer and use it in GitHub Desktop.
Bash OS detection
$regex = "'blblbl'"
if [[ "$OSTYPE" == "linux-gnu" ]]; then
# Linux
$shasum = "/usr/bin/sha1sum"
$strbin = "sed -e$regex"
elif [[ "$OSTYPE" == "darwin"* ]]; then
# Mac OSX
$shasum = "/usr/bin/shasum"
$strbin = "sed -e $regex"
elif [[ "$OSTYPE" == "cygwin" ]]; then
# POSIX compatibility layer and Linux environment emulation for Windows
elif [[ "$OSTYPE" == "msys" ]]; then
# Lightweight shell and GNU utilities compiled for Windows (part of MinGW)
elif [[ "$OSTYPE" == "win32" ]]; then
# I'm not sure this can happen.
elif [[ "$OSTYPE" == "freebsd"* ]]; then
# ...
else
# Unknown.
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment