Last active
December 5, 2023 08:51
-
-
Save MacsInSpace/38cb4d033d936934e433ab625c589bef to your computer and use it in GitHub Desktop.
Detect OS and Architecture cross platform testing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
@echo off | |
goto(){ | |
function checkOS() { | |
unameOut="$(uname -s)" | |
case "${unameOut}" in | |
*Microsoft*) OS="WSL";; #must be first since Windows subsystem for linux will have Linux in the name too | |
*microsoft*) OS="WSL2";; | |
Linux*) OS="Linux";; | |
Darwin*) OS="MacOS";; | |
CYGWIN*) OS="Cygwin";; | |
MINGW*) OS="Windows";; | |
*Msys) OS="Windows";; | |
*) OS="UNKNOWN:${unameOut}" | |
esac | |
echo ${OS} | |
} | |
function checkProcessor() { | |
arch="$(uname -m)" | |
if [[ "$arch" = x86_64* ]]; then | |
if [[ "$(uname -a)" = *ARM64* ]]; then | |
echo 'ARM64' | |
else | |
echo 'x86_64' | |
fi # was going to use /usr/sbin/sysctl -n machdep.cpu.brand_string but this nested if works detecting ARM for now. I think | |
elif [[ "$arch" = i*86 ]]; then | |
echo 'i*86' | |
elif [[ "$arch" = arm* ]]; then | |
echo 'ARM64' | |
elif test "$arch" = aarch64; then | |
echo 'aarch64' | |
else | |
echo "UNKNOWN:${arch}" | |
fi | |
} | |
} | |
checkOS | |
checkProcessor | |
goto $@ | |
read -rsp $'Press enter to continue...\n' | |
exit | |
:(){ | |
rem Windows script here | |
FOR /F "tokens=*" %%o IN ('echo %OS%') do (SET unameOut=%%o) | |
FOR /F "tokens=*" %%p IN ('echo %PROCESSOR_ARCHITECTURE%') do (SET arch=%%p) | |
echo "Operating System is %unameOut%" | |
echo "Processor Architecture is %arch%" | |
rem pause | |
exit |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment