入力がない場合はループプログラム

入力がない場合はループプログラム

このスクリプトは正常に実行されていますが、タイプミスがあってスクリプトを再実行したい場合はどうすればよいですか?

#! /bin/bash
#! userInput - a script that reads in text and outputs it immediately

echo "Would you like to input some text? Y/N"
        read request
if [[ $request = Y ]]; then
        echo "Please input some text"
                read input
        echo $input
elif [[ $request = N ]]; then
        echo "Thank You"
else
        echo "Invalid Input - Please Input Y for yes or N for no"
fi

ベストアンサー1

それがselect目的です。

PS3="Would you like to input some text? <Y/N>   ]"
select choice in "Y" "N"; do
   case $choice in
      "Y")
          echo -n "Please input some text >"
          read input
          echo "$input"
          break
          ;;
      "N")
          echo "Very well."
          break
          ;;
      *)
          echo "Invalid response."
          ;;
    esac
done

おすすめ記事