
Ich habe erfolglos versucht, „while“ und „ask“ zu verwenden, aber das Ziel dieses Skripts besteht darin, einen oder mehrere Befehle auszuführen und dann zu fragen, ob Sie den Befehl wiederholen möchten.
Beispiel:
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
Antwort1
Es gibt vielleicht einen einfacheren Weg, aber zumindest dieser funktioniert.
#!/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