Skip to content

Instantly share code, notes, and snippets.

@trpapp
Created April 9, 2019 14:43
Show Gist options
  • Save trpapp/7fe8f24bd49ccfffa9cc04afa1fc6c05 to your computer and use it in GitHub Desktop.
Save trpapp/7fe8f24bd49ccfffa9cc04afa1fc6c05 to your computer and use it in GitHub Desktop.
Script to check computer's architecture
echo Starting #%0 & @ECHO OFF & GOTO :windows
#### BASH SCRIPT STARTS HERE ####
# Check for OS name, but can't trust uname -a for arch
OS=`uname`
# Detect architecture by abusing an integer overflow
if ((1<<32)); then
ARCH=64 # 64-bit architecture
else
ARCH=32 # 32-bit architecture
fi
# $OS contains OS name, and $ARCH contains the architecture
clear
echo "Hello $OS $ARCH-bit user!"
# Exit before we run into the Windows code
read -n1 -r -p "Press any key to continue..." key
exit
:windows
::#### WINDOWS SCRIPT STARTS HERE ####
:: Determine the architecture by checking Windows' env vars.
IF %PROCESSOR_ARCHITECTURE% == x86 (
SET ARCH=32
) ELSE (
SET ARCH=64
)
:: %ARCH% contains the architecture of the OS
CLS
ECHO Hello Windows %ARCH%-bit user!
:: Exit so the script will not continue into the Linux code
PAUSE
EXIT
@trpapp
Copy link
Author

trpapp commented Apr 9, 2019

Instructions

Windows

  • Double click 'arch.cmd'

Other Operating Systems (in a terminal)

  • Make the script executable >_ chmod 777 arch.cmd
  • Run the script >_ ./arch.cmd

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment