
나는 "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