Bash code for detecting enter key does not work in interactive shell
12:32 09 Mar 2026

I scrounged this together from other answer on this site for code that detects the enter key:

while true
do
    read -r -s -n 1 key
    
    if [[ "$key" == $'\n' ]]
    then
        echo "Breaking loop..."
        break
    fi
done

It doesn't work in the command line though. Why is that?

bash