Last active
August 7, 2021 00:15
-
-
Save bkw777/a20721b09e79eb883683cdae25700c8b to your computer and use it in GitHub Desktop.
Platform detection in bash without external executables (no /bin/uname)
This file contains 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 | |
# Example to detect OS in bash using bash built-in variable $OSTYPE instead of `uname` | |
# platform differences | |
stty_f="-F" SERIAL_TTY_PREFIX=ttyUSB # Default (Linux) | |
case "${OSTYPE,,}" in | |
*bsd*) stty_f="-f" SERIAL_TTY_PREFIX=ttyU ;; # FreeBSD/NetBSD/OpenBSD/etc | |
darwin*) stty_f="-f" SERIAL_TTY_PREFIX=cu.usbserial- ;; # Mac OSX | |
esac | |
x=(/dev/${SERIAL_TTY_PREFIX#/dev/}*) | |
PS3="Which serial port? " | |
select PORT in ${x[*]} ;do [[ -c "$PORT" ]] && break ;done | |
echo "stty ${stty_f} $PORT 19200" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment