Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
看下面的代码
stty cbreak -echo input==`dd if=/dev/tty bs=1 count=1 2>/dev/null` stty -cbreak echo if [ "$input" = "a" ];then echo "the input is a" fi
我如何确定输入是否是shell下的退格键。换句话说,退格的符号是什么。
如果您无法在编辑器中插入文字退格字符,则可以echo -ne '\b'改用。这告诉 echo 禁止发出换行符,并将一些反斜杠转义序列解释为特殊字符。\b是退格:
echo -ne '\b'
\b
if [ "$input" = $(echo -ne '\b') ];then
当我使用 时vi,我可以使用击键^V^H将退格字符放入脚本中。在emacs,它会C-q C-h。
vi
^V^H
emacs
C-q C-h
if [ "$input" = "^H" ];then