How do I exit BASH while loop using modulus operator?Running bash loopWhile loop in ShellCan you help me to understand this explanation of shell quoting?For loop syntax bash scriptExit terminal after running a bash scriptRedirection operator priority in BashDisplay images in a loop using bashMeaning of exit 0, exit 1 and exit 2 in a bash scriptBash - add zero to single digit in while loopRunning a Bash while loop over all similar files

Etiquette around loan refinance - decision is going to cost first broker a lot of money

What's the point of deactivating Num Lock on login screens?

How do I find out when a node was added to an availability group?

Why is the ratio of two extensive quantities always intensive?

Is there a hemisphere-neutral way of specifying a season?

Issue with type force PATH search

Is it unprofessional to ask if a job posting on GlassDoor is real?

How badly should I try to prevent a user from XSSing themselves?

How could indestructible materials be used in power generation?

Watching something be written to a file live with tail

AES: Why is it a good practice to use only the first 16bytes of a hash for encryption?

Should I tell management that I intend to leave due to bad software development practices?

Why is consensus so controversial in Britain?

Find the age of the oldest file in one line or return zero

Can one be a co-translator of a book, if he does not know the language that the book is translated into?

How can saying a song's name be a copyright violation?

Magento 2: Migrate only Customer and orders

Personal Teleportation: From Rags to Riches

90's TV series where a boy goes to another dimension through portal near power lines

Why do I get two different answers for this counting problem?

Why is Collection not simply treated as Collection<?>

Blender 2.8 I can't see vertices, edges or faces in edit mode

Python: return float 1.0 as int 1 but float 1.5 as float 1.5

Do I have a twin with permutated remainders?



How do I exit BASH while loop using modulus operator?


Running bash loopWhile loop in ShellCan you help me to understand this explanation of shell quoting?For loop syntax bash scriptExit terminal after running a bash scriptRedirection operator priority in BashDisplay images in a loop using bashMeaning of exit 0, exit 1 and exit 2 in a bash scriptBash - add zero to single digit in while loopRunning a Bash while loop over all similar files













4















So practically for my assignment I need to break out of a true while loop when the user inputs a number that gives a modulus remainder of 0, ex: (25 % 5 = 0 break loop) Where in my attempt below have I gone wrong?



while true
do
echo "Please input anything here: "
read INPUT

if [ `expr $INPUT % 5` -eq 0 ]; then
echo "you entered wrong"
else
echo "you entered right"
break
fi
done









share|improve this question



















  • 2





    If the assignment specifies bash, then you might consider using its built-in arithmetic expansion syntax e.g. (( INPUT % 5 == 0 ))

    – steeldriver
    2 days ago











  • the loop does not end when entering 25 @steeldriver

    – Roosevelt Mendieta
    2 days ago















4















So practically for my assignment I need to break out of a true while loop when the user inputs a number that gives a modulus remainder of 0, ex: (25 % 5 = 0 break loop) Where in my attempt below have I gone wrong?



while true
do
echo "Please input anything here: "
read INPUT

if [ `expr $INPUT % 5` -eq 0 ]; then
echo "you entered wrong"
else
echo "you entered right"
break
fi
done









share|improve this question



















  • 2





    If the assignment specifies bash, then you might consider using its built-in arithmetic expansion syntax e.g. (( INPUT % 5 == 0 ))

    – steeldriver
    2 days ago











  • the loop does not end when entering 25 @steeldriver

    – Roosevelt Mendieta
    2 days ago













4












4








4








So practically for my assignment I need to break out of a true while loop when the user inputs a number that gives a modulus remainder of 0, ex: (25 % 5 = 0 break loop) Where in my attempt below have I gone wrong?



while true
do
echo "Please input anything here: "
read INPUT

if [ `expr $INPUT % 5` -eq 0 ]; then
echo "you entered wrong"
else
echo "you entered right"
break
fi
done









share|improve this question
















So practically for my assignment I need to break out of a true while loop when the user inputs a number that gives a modulus remainder of 0, ex: (25 % 5 = 0 break loop) Where in my attempt below have I gone wrong?



while true
do
echo "Please input anything here: "
read INPUT

if [ `expr $INPUT % 5` -eq 0 ]; then
echo "you entered wrong"
else
echo "you entered right"
break
fi
done






command-line bash scripts






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 2 days ago







Roosevelt Mendieta

















asked 2 days ago









Roosevelt MendietaRoosevelt Mendieta

4915




4915







  • 2





    If the assignment specifies bash, then you might consider using its built-in arithmetic expansion syntax e.g. (( INPUT % 5 == 0 ))

    – steeldriver
    2 days ago











  • the loop does not end when entering 25 @steeldriver

    – Roosevelt Mendieta
    2 days ago












  • 2





    If the assignment specifies bash, then you might consider using its built-in arithmetic expansion syntax e.g. (( INPUT % 5 == 0 ))

    – steeldriver
    2 days ago











  • the loop does not end when entering 25 @steeldriver

    – Roosevelt Mendieta
    2 days ago







2




2





If the assignment specifies bash, then you might consider using its built-in arithmetic expansion syntax e.g. (( INPUT % 5 == 0 ))

– steeldriver
2 days ago





If the assignment specifies bash, then you might consider using its built-in arithmetic expansion syntax e.g. (( INPUT % 5 == 0 ))

– steeldriver
2 days ago













the loop does not end when entering 25 @steeldriver

– Roosevelt Mendieta
2 days ago





the loop does not end when entering 25 @steeldriver

– Roosevelt Mendieta
2 days ago










4 Answers
4






active

oldest

votes


















7














Move the break from the else part to the if part:



#!/bin/bash

while true
do
echo "Please input anything here: "
read INPUT

if [ `expr $INPUT % 5` -eq 0 ]; then
echo "you entered wrong"
break
else
echo "you entered right"
fi
done





share|improve this answer























  • this doesn't work, when I enter 40 the code exits

    – Roosevelt Mendieta
    2 days ago






  • 6





    @RooseveltMendieta Isn't it what you want? I need to break out of a true while loop when the user inputs a number that gives a modulus remainder of 0. 40%5 is also 0.

    – Kulfy
    2 days ago







  • 2





    @Kulfy i was thinking of division in my head instead of modulus, how embarrassing lol yes this solution in fact does work and is exactly what I needed. I need to go to sleep i've been up to late working on this assignment.

    – Roosevelt Mendieta
    2 days ago











  • @RooseveltMendieta It seems that you changed the original code in your question. So, PerlDuck might need to modify explanation of the answer.

    – Kulfy
    2 days ago











  • i version controlled the code back to it's original state @Kulfy

    – Roosevelt Mendieta
    2 days ago


















5














It works for me according to @steeldriver's tips,




  • make sure you use bash



    #!/bin/bash



  • use the bash syntax for arithmetic evaluation



    ((...))


Otherwise the shellscript can remain the same,



#!/bin/bash

while true
do
echo "Please input anything here: "
read INPUT

if (( INPUT % 5 == 0 )) ; then
echo "you entered right"
break
else
echo "you entered wrong"
fi
done


Edit: You have modified the question. This answer corresponds to a previous version of the question. (It is not clear to me, if you want to break the loop, when there is no remainder or when there is a remainder.)






share|improve this answer
































    4














    Since this is bash script we're talking about, you may want to use read -p and arithmetic evaluation ((...))



    $ while read -p "Enter number:" input ; do (( input%5 == 0 )) && echo "Wrong"; break; || echo "alright"; done
    Enter number:11
    alright
    Enter number:7
    alright
    Enter number:10
    Wrong


    Portably, you might want to use [ aka test



    $ [ $((25%5)) -eq 0 ] && echo "Zero"
    Zero
    $ [ $((26%5)) -eq 0 ] && echo "Zero"
    $





    share|improve this answer
































      0














      There is also an example for trap's usage in Bash-Beginners-Guide



      You can use trap to catch signal to exit your process or whatever you want.



      #!/bin/bash
      # traptest.sh

      trap "echo Booh!;exit" SIGINT SIGTERM
      echo "pid is $$"

      while : # This is the same as "while true".
      do
      sleep 60 # This script is not really doing anything.
      done





      share|improve this answer








      New contributor




      ChingKun Yu is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.















      • 3





        OP's question is basically an assignment, so they do have to use modulo operator and arithmetic, so your answer misses that. Since you're new on the site, I won't downvote the answer, but I suggest you address that part soon. There's many other ways in which you could do arithmetic in Bash, so consider addressing one of them not already mentioned

        – Sergiy Kolodyazhnyy
        yesterday











      Your Answer








      StackExchange.ready(function()
      var channelOptions =
      tags: "".split(" "),
      id: "89"
      ;
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function()
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled)
      StackExchange.using("snippets", function()
      createEditor();
      );

      else
      createEditor();

      );

      function createEditor()
      StackExchange.prepareEditor(
      heartbeatType: 'answer',
      autoActivateHeartbeat: false,
      convertImagesToLinks: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      bindNavPrevention: true,
      postfix: "",
      imageUploader:
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      ,
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      );



      );













      draft saved

      draft discarded


















      StackExchange.ready(
      function ()
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1130696%2fhow-do-i-exit-bash-while-loop-using-modulus-operator%23new-answer', 'question_page');

      );

      Post as a guest















      Required, but never shown

























      4 Answers
      4






      active

      oldest

      votes








      4 Answers
      4






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      7














      Move the break from the else part to the if part:



      #!/bin/bash

      while true
      do
      echo "Please input anything here: "
      read INPUT

      if [ `expr $INPUT % 5` -eq 0 ]; then
      echo "you entered wrong"
      break
      else
      echo "you entered right"
      fi
      done





      share|improve this answer























      • this doesn't work, when I enter 40 the code exits

        – Roosevelt Mendieta
        2 days ago






      • 6





        @RooseveltMendieta Isn't it what you want? I need to break out of a true while loop when the user inputs a number that gives a modulus remainder of 0. 40%5 is also 0.

        – Kulfy
        2 days ago







      • 2





        @Kulfy i was thinking of division in my head instead of modulus, how embarrassing lol yes this solution in fact does work and is exactly what I needed. I need to go to sleep i've been up to late working on this assignment.

        – Roosevelt Mendieta
        2 days ago











      • @RooseveltMendieta It seems that you changed the original code in your question. So, PerlDuck might need to modify explanation of the answer.

        – Kulfy
        2 days ago











      • i version controlled the code back to it's original state @Kulfy

        – Roosevelt Mendieta
        2 days ago















      7














      Move the break from the else part to the if part:



      #!/bin/bash

      while true
      do
      echo "Please input anything here: "
      read INPUT

      if [ `expr $INPUT % 5` -eq 0 ]; then
      echo "you entered wrong"
      break
      else
      echo "you entered right"
      fi
      done





      share|improve this answer























      • this doesn't work, when I enter 40 the code exits

        – Roosevelt Mendieta
        2 days ago






      • 6





        @RooseveltMendieta Isn't it what you want? I need to break out of a true while loop when the user inputs a number that gives a modulus remainder of 0. 40%5 is also 0.

        – Kulfy
        2 days ago







      • 2





        @Kulfy i was thinking of division in my head instead of modulus, how embarrassing lol yes this solution in fact does work and is exactly what I needed. I need to go to sleep i've been up to late working on this assignment.

        – Roosevelt Mendieta
        2 days ago











      • @RooseveltMendieta It seems that you changed the original code in your question. So, PerlDuck might need to modify explanation of the answer.

        – Kulfy
        2 days ago











      • i version controlled the code back to it's original state @Kulfy

        – Roosevelt Mendieta
        2 days ago













      7












      7








      7







      Move the break from the else part to the if part:



      #!/bin/bash

      while true
      do
      echo "Please input anything here: "
      read INPUT

      if [ `expr $INPUT % 5` -eq 0 ]; then
      echo "you entered wrong"
      break
      else
      echo "you entered right"
      fi
      done





      share|improve this answer













      Move the break from the else part to the if part:



      #!/bin/bash

      while true
      do
      echo "Please input anything here: "
      read INPUT

      if [ `expr $INPUT % 5` -eq 0 ]; then
      echo "you entered wrong"
      break
      else
      echo "you entered right"
      fi
      done






      share|improve this answer












      share|improve this answer



      share|improve this answer










      answered 2 days ago









      PerlDuckPerlDuck

      7,94611636




      7,94611636












      • this doesn't work, when I enter 40 the code exits

        – Roosevelt Mendieta
        2 days ago






      • 6





        @RooseveltMendieta Isn't it what you want? I need to break out of a true while loop when the user inputs a number that gives a modulus remainder of 0. 40%5 is also 0.

        – Kulfy
        2 days ago







      • 2





        @Kulfy i was thinking of division in my head instead of modulus, how embarrassing lol yes this solution in fact does work and is exactly what I needed. I need to go to sleep i've been up to late working on this assignment.

        – Roosevelt Mendieta
        2 days ago











      • @RooseveltMendieta It seems that you changed the original code in your question. So, PerlDuck might need to modify explanation of the answer.

        – Kulfy
        2 days ago











      • i version controlled the code back to it's original state @Kulfy

        – Roosevelt Mendieta
        2 days ago

















      • this doesn't work, when I enter 40 the code exits

        – Roosevelt Mendieta
        2 days ago






      • 6





        @RooseveltMendieta Isn't it what you want? I need to break out of a true while loop when the user inputs a number that gives a modulus remainder of 0. 40%5 is also 0.

        – Kulfy
        2 days ago







      • 2





        @Kulfy i was thinking of division in my head instead of modulus, how embarrassing lol yes this solution in fact does work and is exactly what I needed. I need to go to sleep i've been up to late working on this assignment.

        – Roosevelt Mendieta
        2 days ago











      • @RooseveltMendieta It seems that you changed the original code in your question. So, PerlDuck might need to modify explanation of the answer.

        – Kulfy
        2 days ago











      • i version controlled the code back to it's original state @Kulfy

        – Roosevelt Mendieta
        2 days ago
















      this doesn't work, when I enter 40 the code exits

      – Roosevelt Mendieta
      2 days ago





      this doesn't work, when I enter 40 the code exits

      – Roosevelt Mendieta
      2 days ago




      6




      6





      @RooseveltMendieta Isn't it what you want? I need to break out of a true while loop when the user inputs a number that gives a modulus remainder of 0. 40%5 is also 0.

      – Kulfy
      2 days ago






      @RooseveltMendieta Isn't it what you want? I need to break out of a true while loop when the user inputs a number that gives a modulus remainder of 0. 40%5 is also 0.

      – Kulfy
      2 days ago





      2




      2





      @Kulfy i was thinking of division in my head instead of modulus, how embarrassing lol yes this solution in fact does work and is exactly what I needed. I need to go to sleep i've been up to late working on this assignment.

      – Roosevelt Mendieta
      2 days ago





      @Kulfy i was thinking of division in my head instead of modulus, how embarrassing lol yes this solution in fact does work and is exactly what I needed. I need to go to sleep i've been up to late working on this assignment.

      – Roosevelt Mendieta
      2 days ago













      @RooseveltMendieta It seems that you changed the original code in your question. So, PerlDuck might need to modify explanation of the answer.

      – Kulfy
      2 days ago





      @RooseveltMendieta It seems that you changed the original code in your question. So, PerlDuck might need to modify explanation of the answer.

      – Kulfy
      2 days ago













      i version controlled the code back to it's original state @Kulfy

      – Roosevelt Mendieta
      2 days ago





      i version controlled the code back to it's original state @Kulfy

      – Roosevelt Mendieta
      2 days ago













      5














      It works for me according to @steeldriver's tips,




      • make sure you use bash



        #!/bin/bash



      • use the bash syntax for arithmetic evaluation



        ((...))


      Otherwise the shellscript can remain the same,



      #!/bin/bash

      while true
      do
      echo "Please input anything here: "
      read INPUT

      if (( INPUT % 5 == 0 )) ; then
      echo "you entered right"
      break
      else
      echo "you entered wrong"
      fi
      done


      Edit: You have modified the question. This answer corresponds to a previous version of the question. (It is not clear to me, if you want to break the loop, when there is no remainder or when there is a remainder.)






      share|improve this answer





























        5














        It works for me according to @steeldriver's tips,




        • make sure you use bash



          #!/bin/bash



        • use the bash syntax for arithmetic evaluation



          ((...))


        Otherwise the shellscript can remain the same,



        #!/bin/bash

        while true
        do
        echo "Please input anything here: "
        read INPUT

        if (( INPUT % 5 == 0 )) ; then
        echo "you entered right"
        break
        else
        echo "you entered wrong"
        fi
        done


        Edit: You have modified the question. This answer corresponds to a previous version of the question. (It is not clear to me, if you want to break the loop, when there is no remainder or when there is a remainder.)






        share|improve this answer



























          5












          5








          5







          It works for me according to @steeldriver's tips,




          • make sure you use bash



            #!/bin/bash



          • use the bash syntax for arithmetic evaluation



            ((...))


          Otherwise the shellscript can remain the same,



          #!/bin/bash

          while true
          do
          echo "Please input anything here: "
          read INPUT

          if (( INPUT % 5 == 0 )) ; then
          echo "you entered right"
          break
          else
          echo "you entered wrong"
          fi
          done


          Edit: You have modified the question. This answer corresponds to a previous version of the question. (It is not clear to me, if you want to break the loop, when there is no remainder or when there is a remainder.)






          share|improve this answer















          It works for me according to @steeldriver's tips,




          • make sure you use bash



            #!/bin/bash



          • use the bash syntax for arithmetic evaluation



            ((...))


          Otherwise the shellscript can remain the same,



          #!/bin/bash

          while true
          do
          echo "Please input anything here: "
          read INPUT

          if (( INPUT % 5 == 0 )) ; then
          echo "you entered right"
          break
          else
          echo "you entered wrong"
          fi
          done


          Edit: You have modified the question. This answer corresponds to a previous version of the question. (It is not clear to me, if you want to break the loop, when there is no remainder or when there is a remainder.)







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited 2 days ago

























          answered 2 days ago









          sudodussudodus

          25.7k33078




          25.7k33078





















              4














              Since this is bash script we're talking about, you may want to use read -p and arithmetic evaluation ((...))



              $ while read -p "Enter number:" input ; do (( input%5 == 0 )) && echo "Wrong"; break; || echo "alright"; done
              Enter number:11
              alright
              Enter number:7
              alright
              Enter number:10
              Wrong


              Portably, you might want to use [ aka test



              $ [ $((25%5)) -eq 0 ] && echo "Zero"
              Zero
              $ [ $((26%5)) -eq 0 ] && echo "Zero"
              $





              share|improve this answer





























                4














                Since this is bash script we're talking about, you may want to use read -p and arithmetic evaluation ((...))



                $ while read -p "Enter number:" input ; do (( input%5 == 0 )) && echo "Wrong"; break; || echo "alright"; done
                Enter number:11
                alright
                Enter number:7
                alright
                Enter number:10
                Wrong


                Portably, you might want to use [ aka test



                $ [ $((25%5)) -eq 0 ] && echo "Zero"
                Zero
                $ [ $((26%5)) -eq 0 ] && echo "Zero"
                $





                share|improve this answer



























                  4












                  4








                  4







                  Since this is bash script we're talking about, you may want to use read -p and arithmetic evaluation ((...))



                  $ while read -p "Enter number:" input ; do (( input%5 == 0 )) && echo "Wrong"; break; || echo "alright"; done
                  Enter number:11
                  alright
                  Enter number:7
                  alright
                  Enter number:10
                  Wrong


                  Portably, you might want to use [ aka test



                  $ [ $((25%5)) -eq 0 ] && echo "Zero"
                  Zero
                  $ [ $((26%5)) -eq 0 ] && echo "Zero"
                  $





                  share|improve this answer















                  Since this is bash script we're talking about, you may want to use read -p and arithmetic evaluation ((...))



                  $ while read -p "Enter number:" input ; do (( input%5 == 0 )) && echo "Wrong"; break; || echo "alright"; done
                  Enter number:11
                  alright
                  Enter number:7
                  alright
                  Enter number:10
                  Wrong


                  Portably, you might want to use [ aka test



                  $ [ $((25%5)) -eq 0 ] && echo "Zero"
                  Zero
                  $ [ $((26%5)) -eq 0 ] && echo "Zero"
                  $






                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited 2 days ago

























                  answered 2 days ago









                  Sergiy KolodyazhnyySergiy Kolodyazhnyy

                  74.9k9155326




                  74.9k9155326





















                      0














                      There is also an example for trap's usage in Bash-Beginners-Guide



                      You can use trap to catch signal to exit your process or whatever you want.



                      #!/bin/bash
                      # traptest.sh

                      trap "echo Booh!;exit" SIGINT SIGTERM
                      echo "pid is $$"

                      while : # This is the same as "while true".
                      do
                      sleep 60 # This script is not really doing anything.
                      done





                      share|improve this answer








                      New contributor




                      ChingKun Yu is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                      Check out our Code of Conduct.















                      • 3





                        OP's question is basically an assignment, so they do have to use modulo operator and arithmetic, so your answer misses that. Since you're new on the site, I won't downvote the answer, but I suggest you address that part soon. There's many other ways in which you could do arithmetic in Bash, so consider addressing one of them not already mentioned

                        – Sergiy Kolodyazhnyy
                        yesterday















                      0














                      There is also an example for trap's usage in Bash-Beginners-Guide



                      You can use trap to catch signal to exit your process or whatever you want.



                      #!/bin/bash
                      # traptest.sh

                      trap "echo Booh!;exit" SIGINT SIGTERM
                      echo "pid is $$"

                      while : # This is the same as "while true".
                      do
                      sleep 60 # This script is not really doing anything.
                      done





                      share|improve this answer








                      New contributor




                      ChingKun Yu is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                      Check out our Code of Conduct.















                      • 3





                        OP's question is basically an assignment, so they do have to use modulo operator and arithmetic, so your answer misses that. Since you're new on the site, I won't downvote the answer, but I suggest you address that part soon. There's many other ways in which you could do arithmetic in Bash, so consider addressing one of them not already mentioned

                        – Sergiy Kolodyazhnyy
                        yesterday













                      0












                      0








                      0







                      There is also an example for trap's usage in Bash-Beginners-Guide



                      You can use trap to catch signal to exit your process or whatever you want.



                      #!/bin/bash
                      # traptest.sh

                      trap "echo Booh!;exit" SIGINT SIGTERM
                      echo "pid is $$"

                      while : # This is the same as "while true".
                      do
                      sleep 60 # This script is not really doing anything.
                      done





                      share|improve this answer








                      New contributor




                      ChingKun Yu is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                      Check out our Code of Conduct.










                      There is also an example for trap's usage in Bash-Beginners-Guide



                      You can use trap to catch signal to exit your process or whatever you want.



                      #!/bin/bash
                      # traptest.sh

                      trap "echo Booh!;exit" SIGINT SIGTERM
                      echo "pid is $$"

                      while : # This is the same as "while true".
                      do
                      sleep 60 # This script is not really doing anything.
                      done






                      share|improve this answer








                      New contributor




                      ChingKun Yu is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                      Check out our Code of Conduct.









                      share|improve this answer



                      share|improve this answer






                      New contributor




                      ChingKun Yu is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                      Check out our Code of Conduct.









                      answered yesterday









                      ChingKun YuChingKun Yu

                      1




                      1




                      New contributor




                      ChingKun Yu is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                      Check out our Code of Conduct.





                      New contributor





                      ChingKun Yu is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                      Check out our Code of Conduct.






                      ChingKun Yu is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                      Check out our Code of Conduct.







                      • 3





                        OP's question is basically an assignment, so they do have to use modulo operator and arithmetic, so your answer misses that. Since you're new on the site, I won't downvote the answer, but I suggest you address that part soon. There's many other ways in which you could do arithmetic in Bash, so consider addressing one of them not already mentioned

                        – Sergiy Kolodyazhnyy
                        yesterday












                      • 3





                        OP's question is basically an assignment, so they do have to use modulo operator and arithmetic, so your answer misses that. Since you're new on the site, I won't downvote the answer, but I suggest you address that part soon. There's many other ways in which you could do arithmetic in Bash, so consider addressing one of them not already mentioned

                        – Sergiy Kolodyazhnyy
                        yesterday







                      3




                      3





                      OP's question is basically an assignment, so they do have to use modulo operator and arithmetic, so your answer misses that. Since you're new on the site, I won't downvote the answer, but I suggest you address that part soon. There's many other ways in which you could do arithmetic in Bash, so consider addressing one of them not already mentioned

                      – Sergiy Kolodyazhnyy
                      yesterday





                      OP's question is basically an assignment, so they do have to use modulo operator and arithmetic, so your answer misses that. Since you're new on the site, I won't downvote the answer, but I suggest you address that part soon. There's many other ways in which you could do arithmetic in Bash, so consider addressing one of them not already mentioned

                      – Sergiy Kolodyazhnyy
                      yesterday

















                      draft saved

                      draft discarded
















































                      Thanks for contributing an answer to Ask Ubuntu!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid


                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.

                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function ()
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1130696%2fhow-do-i-exit-bash-while-loop-using-modulus-operator%23new-answer', 'question_page');

                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      Tamil (spriik) Luke uk diar | Nawigatjuun

                      Align equal signs while including text over equalitiesAMS align: left aligned text/math plus multicolumn alignmentMultiple alignmentsAligning equations in multiple placesNumbering and aligning an equation with multiple columnsHow to align one equation with another multline equationUsing \ in environments inside the begintabularxNumber equations and preserving alignment of equal signsHow can I align equations to the left and to the right?Double equation alignment problem within align enviromentAligned within align: Why are they right-aligned?

                      Where does the image of a data connector as a sharp metal spike originate from?Where does the concept of infected people turning into zombies only after death originate from?Where does the motif of a reanimated human head originate?Where did the notion that Dragons could speak originate?Where does the archetypal image of the 'Grey' alien come from?Where did the suffix '-Man' originate?Where does the notion of being injured or killed by an illusion originate?Where did the term “sophont” originate?Where does the trope of magic spells being driven by advanced technology originate from?Where did the term “the living impaired” originate?