我正在寫劇本…我不知道出了什麼問題…
!#/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