我正在写剧本……我不知道出了什么问题……
!#/bin/bash
while="true"
while ($while == "true") do
clear
echo "What game would you like to play?"
echo "1. Tetris (bastet)"
read number -P "Enter Number:"
if ( $number == "1" ) then
bastet
clear
read again -P "Would you like to play another game? [y/n]:"
if ($again == "n") then
exit
fi
fi
done
这是我的输出(循环):
What game would you like to play?
1. Tetris (bastet)
没有读取命令的提示
答案1
这就是良好的代码表格格式在查看问题和错误方面发挥作用的地方。问题是你的if 语句永远不允许脚本跳出循环。此外,您还缺少一些回声以及 Steeldriver 和 user4556274 指示的所有其他内容。
我并没有真正对你写的内容进行重新编码,所以你仍然可以感觉到哪里出了问题。
看我的修改:
#!/bin/bash
flag="true"
while [ $flag == "true" ]; do
clear
echo "What game would you like to play?"
echo "1. Tetris (bastet)"
read number -P "Enter Number:"
if [ $number -eq "1" ]; then
bastet
fi
clear
echo "Would you like to play another game? [y/n]:"
read again -P
if [ $again -eq "n" ]; then
exit 1
fi
done