Created
April 9, 2019 14:43
-
-
Save trpapp/7fe8f24bd49ccfffa9cc04afa1fc6c05 to your computer and use it in GitHub Desktop.
Script to check computer's architecture
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
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Instructions
Windows
Other Operating Systems (in a terminal)
chmod 777 arch.cmd
./arch.cmd