bashkeystroke

How to detect TAB key in BASH?


I have this piece of bash code below,

#!/bin/bash

while true; do
read -rsn1 input
if [ "$input" = "a" ]; then
    echo "triggered"
fi
done

It works fine when I press "a" key, however what I really want is trigger something when user press TAB key. How can I make it work? Many thanks for help!


Solution

  • If you do not want the scanning to be split with IFS, then set IFS to empty.

    IFS= read -rsn1 input