Khi sử dụng đọc trong bash, nhấn backspace không xóa ký tự cuối cùng được nhập, nhưng sẽ xuất hiện để thêm một backspace vào bộ đệm đầu vào. Có cách nào tôi có thể thay đổi nó để xóa loại bỏ khóa cuối cùng được gõ từ đầu vào? Nếu thế thì sao?Bash đọc vấn đề hành vi nút backspace
Dưới đây là một ví dụ prog ngắn Tôi đang sử dụng nó với nếu đó là của bất kỳ sự giúp đỡ:
#!/bin/bash
colour(){ #$1=text to colourise $2=colour id
printf "%s%s%s" $(tput setaf $2) "$1" $(tput sgr0)
}
game_over() { #$1=message $2=score
printf "\n%s\n%s\n" "$(colour "Game Over!" 1)" "$1"
printf "Your score: %s\n" "$(colour $2 3)"
exit 0
}
score=0
clear
while true; do
word=$(shuf -n1 /usr/share/dict/words) #random word from dictionary
word=${word,,} #to lower case
len=${#word}
let "timeout=(3+$len)/2"
printf "%s (time %s): " "$(colour $word 2)" "$(colour $timeout 3)"
read -t $timeout -n $len input #read input here
if [ $? -ne 0 ]; then
game_over "You did not answer in time" $score
elif [ "$input" != "$word" ]; then
game_over "You did not type the word correctly" $score;
fi
printf "\n"
let "score+=$timeout"
done
'if! đọc ... ' –