我尝试使用“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