나는 무언가를 테스트하기 위해 기본 스크립트를 작성했습니다. (아무 이유 없이) 다음 줄을 표시하고 싶다고 가정해 보겠습니다.
#!/bin/bash
while true; do
echo -e " _____________________________________"
echo -e "|_____________________________________|"
echo -e "|_____________________________________|"
echo -e "|_____________________________________|"
echo -e "|_____________________________________|"
echo -e "|_____________________________________|"
read -p "Type a letter: " letter
done
입력 a
과 출력이 주어지면 이 프로그램을 정상적으로 사용하면 다음과 같습니다.
user@DESKTOP:/mnt/c/Users/user/Documents$ ./script.sh
_____________________________________
|_____________________________________|
|_____________________________________|
|_____________________________________|
|_____________________________________|
|_____________________________________|
Type a letter: a
_____________________________________
|_____________________________________|
|_____________________________________|
|_____________________________________|
|_____________________________________|
|_____________________________________|
Type a letter:
그러나 터미널에 매우 빠르게 입력을 입력하면 다음과 같이 기술이 깨집니다.
user@DESKTOP:/mnt/c/Users/user/Documents$ ./script.sh
a
_____________________________________
|_____________________________________|
|_____________________________________|
|_____________________________________|
|_____________________________________|
|_____________________________________|
Type a letter: _____________________________________
|_____________________________________|
|_____________________________________|
|_____________________________________|
|_____________________________________|
|_____________________________________|
Type a letter:
\n
나는 이것을 전에 시도한 적이 ------
있으며 작동합니다. 하지만 어떤 경우에는 사용하면 안 됩니다.\n
어떻게 하면 이를 방지할 수 있나요? 감사합니다!
답변1
#!/bin/bash
while true; do
stty -echo
echo -e " _____________________________________"
echo -e "|_____________________________________|"
echo -e "|_____________________________________|"
echo -e "|_____________________________________|"
echo -e "|_____________________________________|"
echo -e "|_____________________________________|"
read -t .1 -n 100 buf
stty echo
read -e -i $buf -p "Type a letter: " letter
done