shell脚本回车换行,bash shell的脚本 - 回车键/确认键
I need to compare my input with Enter/Return key...
read -n1 key
if [ $key == "\n" ]
echo "@@@"
fi
But this is not working.. What is wrong with this code
解決方案
Several issues with the posted code. Inline comments detail what to fix:
#!/bin/bash
# ^^ Bash, not sh, must be used for read options
read -s -n 1 key # -s: do not echo input character. -n 1: read only 1 character (separate with space)
# double brackets to test, single equals sign, empty string for just 'enter' in this case...
# if [[ ... ]] is followed by semicolon and 'then' keyword
if [[ $key = "" ]]; then
echo 'You pressed enter!'
else
echo "You pressed '$key'"
fi
總結(jié)
以上是生活随笔為你收集整理的shell脚本回车换行,bash shell的脚本 - 回车键/确认键的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 学习笔记(08):区块链应用案例-区块链
- 下一篇: 秉火429笔记之十三 通信基本概念