Bash Shell Scripting - detect the Enter key

前端 未结 5 1497
时光取名叫无心
时光取名叫无心 2020-12-14 02:21

I need to compare my input with Enter/Return key...

read -n1 key
if [ $key == \"\\n\" ]
   echo \"@@@\"
fi

But this

5条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-14 02:57

    None of these conditions worked for me and so I've came up with this one:

    ${key} = $'\0A'
    

    Tested on CentOS with Bash 4.2.46.

提交回复
热议问题