答案 0 :(得分:0)
请参阅此主题以了解如何记录击键:bash scripting - read single keystroke including special keys enter and space
但是,您还需要使用need来回显提供给相同行的选项,而不是编写新行:How to show and update echo on same line
所以在这种情况下,你的脚本看起来像:
#!/bin/bash
SELECT=""
while [[ "$SELECT" != $'\x0a' && "$SELECT" != $'\x20' ]]; do
echo "Press <Space> to move selection"
echo "Press <Enter> to confirm selection"
read -d'' -s -n1
echo "Debug/$SELECT/${#SELECT}"
[[ "$SELECT" == $'\x0a' ]] && echo "enter" # do your install stuff
[[ "$SELECT" == $'\x20' ]] && echo "space" && echo -ne "$options" # reprint options
done
编辑:实际上printf
在这种情况下可能会更好。