首页 > 解决方案 > 如何检测 BASH 中的 TAB 键?

问题描述

我在下面有这段 bash 代码,

#!/bin/bash

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

当我按下“a”键时它工作正常,但是我真正想要的是当用户按下 TAB 键时触发一些东西。我怎样才能让它工作?非常感谢您的帮助!

标签: bashkeystroke

解决方案


如果您不希望使用 分割扫描IFS,则设置IFS为空。

IFS= read -rsn1 input

推荐阅读