I've got the script below. after running this script, my terminal is broken. my input is not echoed to me, though it is read. I can still run commands. output from commands to stdout is broken: newlines are replaced with long sequences of spaces, so all output is on one very long line. I can use the reset command to fix the terminal.
if I change the SIGKILL to SIGTERM, it is fine. I know that SIGKILL doesn't give the program a chance to shutdown gracefully, but what exactly is going on? what important part of the graceful shutdown is missing that ends up breaking the terminal?
if I remove sudo from the kill command, the same breakage happens. if I remove sudo and change the signal to SIGTERM, then the script hangs on the wait command until the first command exits (presumably the SIGTERM was delivered and ignored).
#!/usr/bin/env bash
sudo sleep 3 >/dev/null 2>&1 </dev/null &
pid=$!