#!/bin/bash current_tty=$(tty) ttys=$(ps aux | grep "$(basename "$SHELL")$" | grep "^$USER\s" | awk '{print("/dev/"$7)}' | grep -v "$current_tty") while getopts ":l :d :c :s" opt; do # shellcheck disable=SC2213 case $opt in l) echo -e "$current_tty - Current\n$ttys" | sort ;; d) for i in $ttys do echo -e "\nkan: detect: $i" > "$i" & done ;; c) echo "$current_tty" ;; s) read -r input_text for i in $ttys do echo "$input_text" > "$i" done ;; \?) echo "Invalid option: -$OPTARG" >&2 ;; esac done