#!/bin/bash #scriptname: quiz read answer?"Who was the u.s. President in 1992? " while [[ $anawex "Buah”]] do print: "wrong try again! " read answer done print Good guess!
时间: 2024-02-18 17:58:59 浏览: 57
这段脚本存在一些语法错误,可能无法正常运行。以下是修正后的脚本:
```
#!/bin/bash
# scriptname: quiz
read -p "Who was the U.S. President in 1992? " answer
while [[ $answer != "Bill Clinton" ]]
do
echo "Wrong answer! Please try again."
read -p "Who was the U.S. President in 1992? " answer
done
echo "Good guess!"
```
修正后的脚本使用了正确的语法,通过 read 命令从标准输入读取用户输入,并使用 while 循环判断用户的答案是否正确。如果答案不正确,会输出提示信息并再次读取用户的输入,直到回答正确为止。最后,输出提示信息表扬用户的猜测。
阅读全文