Skip to content

Instantly share code, notes, and snippets.

@waveform80
Created January 30, 2020 14:59
Show Gist options
  • Save waveform80/bfd5808e131e58fb26ce13ffc6555397 to your computer and use it in GitHub Desktop.
Save waveform80/bfd5808e131e58fb26ce13ffc6555397 to your computer and use it in GitHub Desktop.
a brutally simple serial term
#!/bin/bash
# Derived from https://unix.stackexchange.com/a/311680/295309
if [[ $# -lt 1 ]]; then
echo "Usage:"
echo " $0 <serial-port> [ <speed> [ <stty-options> ...] ]"
echo " Example: $0 /dev/ttyS0 115200"
echo " Use ^Q to quit"
exit 1
fi
set -e
orig_settings=$(stty -g)
trap 'set +e; kill "$catpid"; stty "$orig_settings"' EXIT
port="$1"; shift
stty -F "$port" raw -echo "$@"
# Pass thru *everything* except Ctrl+Q (which sends SIGINT to this)
stty raw -echo isig intr ^Q quit undef susp undef
cat "$port" & catpid=$!
cat >"$port"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment