How to re-run the case statement if the input is invalid? [duplicate]

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
6
down vote

favorite













This question already has an answer here:



  • How to repeat prompt to user in a shell script?

    2 answers



I have the following code in the middle of a script to confirm whether we want to resume the script or not.



read -r -p "Would you like to continue [Y/N] : " i
case $i in
[yY])
echo -e "Resuming the script";;
[nN])
echo -e "Skipped and exit script"
exit 1;;
*)
echo "Invalid Option"
;;
esac


I would like to know is there any way to know is there any way to recall the switch-case if the input option is invalid?







share|improve this question














marked as duplicate by Jeff Schaller, G-Man, Thomas, SivaPrasath, Romeo Ninov Sep 4 at 11:43


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.










  • 1




    You need to rerun the switch case if the input is other than Y and N, am i right?
    – SivaPrasath
    Sep 3 at 16:30











  • Sivaprasath, Yes
    – user308897
    Sep 3 at 16:30










  • Use functions from the main level of your script so that you can control flow more easily.
    – slm♦
    Sep 3 at 16:31







  • 1




    If it's bash, you can use select statement - that one doesn't exit until you have valid input, IIRC
    – Sergiy Kolodyazhnyy
    Sep 3 at 18:47














up vote
6
down vote

favorite













This question already has an answer here:



  • How to repeat prompt to user in a shell script?

    2 answers



I have the following code in the middle of a script to confirm whether we want to resume the script or not.



read -r -p "Would you like to continue [Y/N] : " i
case $i in
[yY])
echo -e "Resuming the script";;
[nN])
echo -e "Skipped and exit script"
exit 1;;
*)
echo "Invalid Option"
;;
esac


I would like to know is there any way to know is there any way to recall the switch-case if the input option is invalid?







share|improve this question














marked as duplicate by Jeff Schaller, G-Man, Thomas, SivaPrasath, Romeo Ninov Sep 4 at 11:43


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.










  • 1




    You need to rerun the switch case if the input is other than Y and N, am i right?
    – SivaPrasath
    Sep 3 at 16:30











  • Sivaprasath, Yes
    – user308897
    Sep 3 at 16:30










  • Use functions from the main level of your script so that you can control flow more easily.
    – slm♦
    Sep 3 at 16:31







  • 1




    If it's bash, you can use select statement - that one doesn't exit until you have valid input, IIRC
    – Sergiy Kolodyazhnyy
    Sep 3 at 18:47












up vote
6
down vote

favorite









up vote
6
down vote

favorite












This question already has an answer here:



  • How to repeat prompt to user in a shell script?

    2 answers



I have the following code in the middle of a script to confirm whether we want to resume the script or not.



read -r -p "Would you like to continue [Y/N] : " i
case $i in
[yY])
echo -e "Resuming the script";;
[nN])
echo -e "Skipped and exit script"
exit 1;;
*)
echo "Invalid Option"
;;
esac


I would like to know is there any way to know is there any way to recall the switch-case if the input option is invalid?







share|improve this question















This question already has an answer here:



  • How to repeat prompt to user in a shell script?

    2 answers



I have the following code in the middle of a script to confirm whether we want to resume the script or not.



read -r -p "Would you like to continue [Y/N] : " i
case $i in
[yY])
echo -e "Resuming the script";;
[nN])
echo -e "Skipped and exit script"
exit 1;;
*)
echo "Invalid Option"
;;
esac


I would like to know is there any way to know is there any way to recall the switch-case if the input option is invalid?





This question already has an answer here:



  • How to repeat prompt to user in a shell script?

    2 answers









share|improve this question













share|improve this question




share|improve this question








edited Sep 3 at 17:18









Kusalananda

105k14209326




105k14209326










asked Sep 3 at 16:27







user308897











marked as duplicate by Jeff Schaller, G-Man, Thomas, SivaPrasath, Romeo Ninov Sep 4 at 11:43


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.






marked as duplicate by Jeff Schaller, G-Man, Thomas, SivaPrasath, Romeo Ninov Sep 4 at 11:43


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.









  • 1




    You need to rerun the switch case if the input is other than Y and N, am i right?
    – SivaPrasath
    Sep 3 at 16:30











  • Sivaprasath, Yes
    – user308897
    Sep 3 at 16:30










  • Use functions from the main level of your script so that you can control flow more easily.
    – slm♦
    Sep 3 at 16:31







  • 1




    If it's bash, you can use select statement - that one doesn't exit until you have valid input, IIRC
    – Sergiy Kolodyazhnyy
    Sep 3 at 18:47












  • 1




    You need to rerun the switch case if the input is other than Y and N, am i right?
    – SivaPrasath
    Sep 3 at 16:30











  • Sivaprasath, Yes
    – user308897
    Sep 3 at 16:30










  • Use functions from the main level of your script so that you can control flow more easily.
    – slm♦
    Sep 3 at 16:31







  • 1




    If it's bash, you can use select statement - that one doesn't exit until you have valid input, IIRC
    – Sergiy Kolodyazhnyy
    Sep 3 at 18:47







1




1




You need to rerun the switch case if the input is other than Y and N, am i right?
– SivaPrasath
Sep 3 at 16:30





You need to rerun the switch case if the input is other than Y and N, am i right?
– SivaPrasath
Sep 3 at 16:30













Sivaprasath, Yes
– user308897
Sep 3 at 16:30




Sivaprasath, Yes
– user308897
Sep 3 at 16:30












Use functions from the main level of your script so that you can control flow more easily.
– slm♦
Sep 3 at 16:31





Use functions from the main level of your script so that you can control flow more easily.
– slm♦
Sep 3 at 16:31





1




1




If it's bash, you can use select statement - that one doesn't exit until you have valid input, IIRC
– Sergiy Kolodyazhnyy
Sep 3 at 18:47




If it's bash, you can use select statement - that one doesn't exit until you have valid input, IIRC
– Sergiy Kolodyazhnyy
Sep 3 at 18:47










4 Answers
4






active

oldest

votes

















up vote
12
down vote













Do your input in a loop. Exit the loop with break (or exit as the case may be) if you get a valid response from the user.



while true; do
read -p 'Continue? yes/no: ' input
case $input in
[yY]*)
echo 'Continuing'
break
;;
[nN]*)
echo 'Ok, exiting'
exit 1
;;
*)
echo 'Invalid input' >&2
esac
done


As a utility function:



ask_continue () 
while true; do
read -p 'Continue? yes/no: ' input
case $input in
[yY]*)
echo 'Continuing'
break
;;
[nN]*)
echo 'Ok, exiting'
exit 1
;;
*)
echo 'Invalid input' >&2
esac
done



A variation of the utility function that allows exiting through EOF (e.g. pressing Ctrl+D):



ask_continue () 
while read -p 'Continue? yes/no: ' input; do
case $input in
[yY]*)
echo 'Continuing'
return
;;
[nN]*)
break
;;
*)
echo 'Invalid input' >&2
esac
done

echo 'Ok, exiting'
exit 1



Here, there are three ways out of the loop:



  1. The user enters "yes", in which case the function returns.

  2. The user enters "no", in which case the we break out of the loop and execute exit 1.

  3. The read fails due to something like encountering an end-of-input or some other error, in which case the exit 1 is executed.





share|improve this answer






















  • You may also want to exit the script upon empty input (EOF).
    – Stéphane Chazelas
    Sep 3 at 22:14










  • @StéphaneChazelas Yes, definitely. I'll update in the morning. Thanks.
    – Kusalananda
    Sep 3 at 22:45

















up vote
6
down vote













Why not just repeating the read?



unset i
while [[ ! "$i" =~ ^[yYnN]$ ]]; do read -r -p "Would you like to continue [Y/N] : " i; done





share|improve this answer



























    up vote
    3
    down vote













    You can do by keeping switch case inside a function.



    function testCase ()

    read -r -p "Would you like to continue [Y/N] : " i
    case $i in
    [yY])
    echo -e "Resuming the script";;
    [nN])
    echo -e "Skipped and exit script"
    exit 1;;
    *)
    echo "Invalid Option"
    testCase
    ;;
    esac

    testCase


    If the input is invalid it will recall the function until it gets a valid input.






    share|improve this answer
















    • 3




      Or until you run into a resource restriction or a maximum recursion depth limit.
      – Kusalananda
      Sep 3 at 16:35











    • Thanks a lot it works!!
      – user308897
      Sep 3 at 16:42






    • 8




      I wouldn't count on the shell being able to optimize the tail recursion, and given the usual procedural nature of shell scripts, I'd really suggest writing that loop out.
      – ilkkachu
      Sep 3 at 18:33







    • 1




      @Kusalananda If the user gives an incorrect answer to a simple yes/no question so many times you hit the recursion limit, he deserves to have the script crash.
      – Barmar
      Sep 3 at 21:45










    • @Barmar A programmer should expect that the user will input anything, whether it's an incorrect answer enough times to hit a recursion limit, or eight gigabytes of null and control codes. Failing on a corner case like this is indicative of bad programming.
      – forest
      Sep 4 at 0:47


















    up vote
    1
    down vote













    until [ "$i" = "0" ]
    do
    read -r -p "Would you like to continue [Y/N] : " i
    case $i in
    [yY])
    echo -e "Resuming the script";;
    [nN])
    echo -e "Skipped and exit script"
    exit 1;;
    *)
    echo "Invalid Option"
    ;;
    esac
    done





    share|improve this answer


























      4 Answers
      4






      active

      oldest

      votes








      4 Answers
      4






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes








      up vote
      12
      down vote













      Do your input in a loop. Exit the loop with break (or exit as the case may be) if you get a valid response from the user.



      while true; do
      read -p 'Continue? yes/no: ' input
      case $input in
      [yY]*)
      echo 'Continuing'
      break
      ;;
      [nN]*)
      echo 'Ok, exiting'
      exit 1
      ;;
      *)
      echo 'Invalid input' >&2
      esac
      done


      As a utility function:



      ask_continue () 
      while true; do
      read -p 'Continue? yes/no: ' input
      case $input in
      [yY]*)
      echo 'Continuing'
      break
      ;;
      [nN]*)
      echo 'Ok, exiting'
      exit 1
      ;;
      *)
      echo 'Invalid input' >&2
      esac
      done



      A variation of the utility function that allows exiting through EOF (e.g. pressing Ctrl+D):



      ask_continue () 
      while read -p 'Continue? yes/no: ' input; do
      case $input in
      [yY]*)
      echo 'Continuing'
      return
      ;;
      [nN]*)
      break
      ;;
      *)
      echo 'Invalid input' >&2
      esac
      done

      echo 'Ok, exiting'
      exit 1



      Here, there are three ways out of the loop:



      1. The user enters "yes", in which case the function returns.

      2. The user enters "no", in which case the we break out of the loop and execute exit 1.

      3. The read fails due to something like encountering an end-of-input or some other error, in which case the exit 1 is executed.





      share|improve this answer






















      • You may also want to exit the script upon empty input (EOF).
        – Stéphane Chazelas
        Sep 3 at 22:14










      • @StéphaneChazelas Yes, definitely. I'll update in the morning. Thanks.
        – Kusalananda
        Sep 3 at 22:45














      up vote
      12
      down vote













      Do your input in a loop. Exit the loop with break (or exit as the case may be) if you get a valid response from the user.



      while true; do
      read -p 'Continue? yes/no: ' input
      case $input in
      [yY]*)
      echo 'Continuing'
      break
      ;;
      [nN]*)
      echo 'Ok, exiting'
      exit 1
      ;;
      *)
      echo 'Invalid input' >&2
      esac
      done


      As a utility function:



      ask_continue () 
      while true; do
      read -p 'Continue? yes/no: ' input
      case $input in
      [yY]*)
      echo 'Continuing'
      break
      ;;
      [nN]*)
      echo 'Ok, exiting'
      exit 1
      ;;
      *)
      echo 'Invalid input' >&2
      esac
      done



      A variation of the utility function that allows exiting through EOF (e.g. pressing Ctrl+D):



      ask_continue () 
      while read -p 'Continue? yes/no: ' input; do
      case $input in
      [yY]*)
      echo 'Continuing'
      return
      ;;
      [nN]*)
      break
      ;;
      *)
      echo 'Invalid input' >&2
      esac
      done

      echo 'Ok, exiting'
      exit 1



      Here, there are three ways out of the loop:



      1. The user enters "yes", in which case the function returns.

      2. The user enters "no", in which case the we break out of the loop and execute exit 1.

      3. The read fails due to something like encountering an end-of-input or some other error, in which case the exit 1 is executed.





      share|improve this answer






















      • You may also want to exit the script upon empty input (EOF).
        – Stéphane Chazelas
        Sep 3 at 22:14










      • @StéphaneChazelas Yes, definitely. I'll update in the morning. Thanks.
        – Kusalananda
        Sep 3 at 22:45












      up vote
      12
      down vote










      up vote
      12
      down vote









      Do your input in a loop. Exit the loop with break (or exit as the case may be) if you get a valid response from the user.



      while true; do
      read -p 'Continue? yes/no: ' input
      case $input in
      [yY]*)
      echo 'Continuing'
      break
      ;;
      [nN]*)
      echo 'Ok, exiting'
      exit 1
      ;;
      *)
      echo 'Invalid input' >&2
      esac
      done


      As a utility function:



      ask_continue () 
      while true; do
      read -p 'Continue? yes/no: ' input
      case $input in
      [yY]*)
      echo 'Continuing'
      break
      ;;
      [nN]*)
      echo 'Ok, exiting'
      exit 1
      ;;
      *)
      echo 'Invalid input' >&2
      esac
      done



      A variation of the utility function that allows exiting through EOF (e.g. pressing Ctrl+D):



      ask_continue () 
      while read -p 'Continue? yes/no: ' input; do
      case $input in
      [yY]*)
      echo 'Continuing'
      return
      ;;
      [nN]*)
      break
      ;;
      *)
      echo 'Invalid input' >&2
      esac
      done

      echo 'Ok, exiting'
      exit 1



      Here, there are three ways out of the loop:



      1. The user enters "yes", in which case the function returns.

      2. The user enters "no", in which case the we break out of the loop and execute exit 1.

      3. The read fails due to something like encountering an end-of-input or some other error, in which case the exit 1 is executed.





      share|improve this answer














      Do your input in a loop. Exit the loop with break (or exit as the case may be) if you get a valid response from the user.



      while true; do
      read -p 'Continue? yes/no: ' input
      case $input in
      [yY]*)
      echo 'Continuing'
      break
      ;;
      [nN]*)
      echo 'Ok, exiting'
      exit 1
      ;;
      *)
      echo 'Invalid input' >&2
      esac
      done


      As a utility function:



      ask_continue () 
      while true; do
      read -p 'Continue? yes/no: ' input
      case $input in
      [yY]*)
      echo 'Continuing'
      break
      ;;
      [nN]*)
      echo 'Ok, exiting'
      exit 1
      ;;
      *)
      echo 'Invalid input' >&2
      esac
      done



      A variation of the utility function that allows exiting through EOF (e.g. pressing Ctrl+D):



      ask_continue () 
      while read -p 'Continue? yes/no: ' input; do
      case $input in
      [yY]*)
      echo 'Continuing'
      return
      ;;
      [nN]*)
      break
      ;;
      *)
      echo 'Invalid input' >&2
      esac
      done

      echo 'Ok, exiting'
      exit 1



      Here, there are three ways out of the loop:



      1. The user enters "yes", in which case the function returns.

      2. The user enters "no", in which case the we break out of the loop and execute exit 1.

      3. The read fails due to something like encountering an end-of-input or some other error, in which case the exit 1 is executed.






      share|improve this answer














      share|improve this answer



      share|improve this answer








      edited Sep 4 at 5:58

























      answered Sep 3 at 16:41









      Kusalananda

      105k14209326




      105k14209326











      • You may also want to exit the script upon empty input (EOF).
        – Stéphane Chazelas
        Sep 3 at 22:14










      • @StéphaneChazelas Yes, definitely. I'll update in the morning. Thanks.
        – Kusalananda
        Sep 3 at 22:45
















      • You may also want to exit the script upon empty input (EOF).
        – Stéphane Chazelas
        Sep 3 at 22:14










      • @StéphaneChazelas Yes, definitely. I'll update in the morning. Thanks.
        – Kusalananda
        Sep 3 at 22:45















      You may also want to exit the script upon empty input (EOF).
      – Stéphane Chazelas
      Sep 3 at 22:14




      You may also want to exit the script upon empty input (EOF).
      – Stéphane Chazelas
      Sep 3 at 22:14












      @StéphaneChazelas Yes, definitely. I'll update in the morning. Thanks.
      – Kusalananda
      Sep 3 at 22:45




      @StéphaneChazelas Yes, definitely. I'll update in the morning. Thanks.
      – Kusalananda
      Sep 3 at 22:45












      up vote
      6
      down vote













      Why not just repeating the read?



      unset i
      while [[ ! "$i" =~ ^[yYnN]$ ]]; do read -r -p "Would you like to continue [Y/N] : " i; done





      share|improve this answer
























        up vote
        6
        down vote













        Why not just repeating the read?



        unset i
        while [[ ! "$i" =~ ^[yYnN]$ ]]; do read -r -p "Would you like to continue [Y/N] : " i; done





        share|improve this answer






















          up vote
          6
          down vote










          up vote
          6
          down vote









          Why not just repeating the read?



          unset i
          while [[ ! "$i" =~ ^[yYnN]$ ]]; do read -r -p "Would you like to continue [Y/N] : " i; done





          share|improve this answer












          Why not just repeating the read?



          unset i
          while [[ ! "$i" =~ ^[yYnN]$ ]]; do read -r -p "Would you like to continue [Y/N] : " i; done






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Sep 3 at 16:46









          RudiC

          1,1616




          1,1616




















              up vote
              3
              down vote













              You can do by keeping switch case inside a function.



              function testCase ()

              read -r -p "Would you like to continue [Y/N] : " i
              case $i in
              [yY])
              echo -e "Resuming the script";;
              [nN])
              echo -e "Skipped and exit script"
              exit 1;;
              *)
              echo "Invalid Option"
              testCase
              ;;
              esac

              testCase


              If the input is invalid it will recall the function until it gets a valid input.






              share|improve this answer
















              • 3




                Or until you run into a resource restriction or a maximum recursion depth limit.
                – Kusalananda
                Sep 3 at 16:35











              • Thanks a lot it works!!
                – user308897
                Sep 3 at 16:42






              • 8




                I wouldn't count on the shell being able to optimize the tail recursion, and given the usual procedural nature of shell scripts, I'd really suggest writing that loop out.
                – ilkkachu
                Sep 3 at 18:33







              • 1




                @Kusalananda If the user gives an incorrect answer to a simple yes/no question so many times you hit the recursion limit, he deserves to have the script crash.
                – Barmar
                Sep 3 at 21:45










              • @Barmar A programmer should expect that the user will input anything, whether it's an incorrect answer enough times to hit a recursion limit, or eight gigabytes of null and control codes. Failing on a corner case like this is indicative of bad programming.
                – forest
                Sep 4 at 0:47















              up vote
              3
              down vote













              You can do by keeping switch case inside a function.



              function testCase ()

              read -r -p "Would you like to continue [Y/N] : " i
              case $i in
              [yY])
              echo -e "Resuming the script";;
              [nN])
              echo -e "Skipped and exit script"
              exit 1;;
              *)
              echo "Invalid Option"
              testCase
              ;;
              esac

              testCase


              If the input is invalid it will recall the function until it gets a valid input.






              share|improve this answer
















              • 3




                Or until you run into a resource restriction or a maximum recursion depth limit.
                – Kusalananda
                Sep 3 at 16:35











              • Thanks a lot it works!!
                – user308897
                Sep 3 at 16:42






              • 8




                I wouldn't count on the shell being able to optimize the tail recursion, and given the usual procedural nature of shell scripts, I'd really suggest writing that loop out.
                – ilkkachu
                Sep 3 at 18:33







              • 1




                @Kusalananda If the user gives an incorrect answer to a simple yes/no question so many times you hit the recursion limit, he deserves to have the script crash.
                – Barmar
                Sep 3 at 21:45










              • @Barmar A programmer should expect that the user will input anything, whether it's an incorrect answer enough times to hit a recursion limit, or eight gigabytes of null and control codes. Failing on a corner case like this is indicative of bad programming.
                – forest
                Sep 4 at 0:47













              up vote
              3
              down vote










              up vote
              3
              down vote









              You can do by keeping switch case inside a function.



              function testCase ()

              read -r -p "Would you like to continue [Y/N] : " i
              case $i in
              [yY])
              echo -e "Resuming the script";;
              [nN])
              echo -e "Skipped and exit script"
              exit 1;;
              *)
              echo "Invalid Option"
              testCase
              ;;
              esac

              testCase


              If the input is invalid it will recall the function until it gets a valid input.






              share|improve this answer












              You can do by keeping switch case inside a function.



              function testCase ()

              read -r -p "Would you like to continue [Y/N] : " i
              case $i in
              [yY])
              echo -e "Resuming the script";;
              [nN])
              echo -e "Skipped and exit script"
              exit 1;;
              *)
              echo "Invalid Option"
              testCase
              ;;
              esac

              testCase


              If the input is invalid it will recall the function until it gets a valid input.







              share|improve this answer












              share|improve this answer



              share|improve this answer










              answered Sep 3 at 16:33









              SivaPrasath

              1




              1







              • 3




                Or until you run into a resource restriction or a maximum recursion depth limit.
                – Kusalananda
                Sep 3 at 16:35











              • Thanks a lot it works!!
                – user308897
                Sep 3 at 16:42






              • 8




                I wouldn't count on the shell being able to optimize the tail recursion, and given the usual procedural nature of shell scripts, I'd really suggest writing that loop out.
                – ilkkachu
                Sep 3 at 18:33







              • 1




                @Kusalananda If the user gives an incorrect answer to a simple yes/no question so many times you hit the recursion limit, he deserves to have the script crash.
                – Barmar
                Sep 3 at 21:45










              • @Barmar A programmer should expect that the user will input anything, whether it's an incorrect answer enough times to hit a recursion limit, or eight gigabytes of null and control codes. Failing on a corner case like this is indicative of bad programming.
                – forest
                Sep 4 at 0:47













              • 3




                Or until you run into a resource restriction or a maximum recursion depth limit.
                – Kusalananda
                Sep 3 at 16:35











              • Thanks a lot it works!!
                – user308897
                Sep 3 at 16:42






              • 8




                I wouldn't count on the shell being able to optimize the tail recursion, and given the usual procedural nature of shell scripts, I'd really suggest writing that loop out.
                – ilkkachu
                Sep 3 at 18:33







              • 1




                @Kusalananda If the user gives an incorrect answer to a simple yes/no question so many times you hit the recursion limit, he deserves to have the script crash.
                – Barmar
                Sep 3 at 21:45










              • @Barmar A programmer should expect that the user will input anything, whether it's an incorrect answer enough times to hit a recursion limit, or eight gigabytes of null and control codes. Failing on a corner case like this is indicative of bad programming.
                – forest
                Sep 4 at 0:47








              3




              3




              Or until you run into a resource restriction or a maximum recursion depth limit.
              – Kusalananda
              Sep 3 at 16:35





              Or until you run into a resource restriction or a maximum recursion depth limit.
              – Kusalananda
              Sep 3 at 16:35













              Thanks a lot it works!!
              – user308897
              Sep 3 at 16:42




              Thanks a lot it works!!
              – user308897
              Sep 3 at 16:42




              8




              8




              I wouldn't count on the shell being able to optimize the tail recursion, and given the usual procedural nature of shell scripts, I'd really suggest writing that loop out.
              – ilkkachu
              Sep 3 at 18:33





              I wouldn't count on the shell being able to optimize the tail recursion, and given the usual procedural nature of shell scripts, I'd really suggest writing that loop out.
              – ilkkachu
              Sep 3 at 18:33





              1




              1




              @Kusalananda If the user gives an incorrect answer to a simple yes/no question so many times you hit the recursion limit, he deserves to have the script crash.
              – Barmar
              Sep 3 at 21:45




              @Kusalananda If the user gives an incorrect answer to a simple yes/no question so many times you hit the recursion limit, he deserves to have the script crash.
              – Barmar
              Sep 3 at 21:45












              @Barmar A programmer should expect that the user will input anything, whether it's an incorrect answer enough times to hit a recursion limit, or eight gigabytes of null and control codes. Failing on a corner case like this is indicative of bad programming.
              – forest
              Sep 4 at 0:47





              @Barmar A programmer should expect that the user will input anything, whether it's an incorrect answer enough times to hit a recursion limit, or eight gigabytes of null and control codes. Failing on a corner case like this is indicative of bad programming.
              – forest
              Sep 4 at 0:47











              up vote
              1
              down vote













              until [ "$i" = "0" ]
              do
              read -r -p "Would you like to continue [Y/N] : " i
              case $i in
              [yY])
              echo -e "Resuming the script";;
              [nN])
              echo -e "Skipped and exit script"
              exit 1;;
              *)
              echo "Invalid Option"
              ;;
              esac
              done





              share|improve this answer
























                up vote
                1
                down vote













                until [ "$i" = "0" ]
                do
                read -r -p "Would you like to continue [Y/N] : " i
                case $i in
                [yY])
                echo -e "Resuming the script";;
                [nN])
                echo -e "Skipped and exit script"
                exit 1;;
                *)
                echo "Invalid Option"
                ;;
                esac
                done





                share|improve this answer






















                  up vote
                  1
                  down vote










                  up vote
                  1
                  down vote









                  until [ "$i" = "0" ]
                  do
                  read -r -p "Would you like to continue [Y/N] : " i
                  case $i in
                  [yY])
                  echo -e "Resuming the script";;
                  [nN])
                  echo -e "Skipped and exit script"
                  exit 1;;
                  *)
                  echo "Invalid Option"
                  ;;
                  esac
                  done





                  share|improve this answer












                  until [ "$i" = "0" ]
                  do
                  read -r -p "Would you like to continue [Y/N] : " i
                  case $i in
                  [yY])
                  echo -e "Resuming the script";;
                  [nN])
                  echo -e "Skipped and exit script"
                  exit 1;;
                  *)
                  echo "Invalid Option"
                  ;;
                  esac
                  done






                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Sep 3 at 18:21









                  GAD3R

                  22.7k154895




                  22.7k154895












                      Comments

                      Popular posts from this blog

                      What does second last employer means? [closed]

                      Installing NextGIS Connect into QGIS 3?

                      One-line joke