
我嘗試使用“while”和“ask”但沒有成功,但此腳本的整體目標是運行一個或多個命令,然後詢問您是否要再次重複該命令。
例子:
echo "adding a whatever... stand by..."
# prompt for yes or no to repeat the above command. If no go to the next command.
echo "Done adding."
exit 0
答案1
可能有一種更簡單的方法,但這至少會起作用。
#!/bin/bash
_repeat="Y"
while [ $_repeat = "Y" ]
do
# Do whatever your tasks are
# Prompt for repeat
echo -n "Repeat? (Y/N)"
read -n1 Input
echo # Completes the line
case $Input in
[Nn]):
_repeat="N"
;;
esac
done