bash - stop a command within a loop but continue the loop

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











up vote
0
down vote

favorite












I'm running a loop like this:



for ip in 10.0.0.1 10.0.0.2 10.0.0.3; do traceroute $ip; done


I want to be able to kill the current traceroute when it gets boring (and before its 30-hop max), and move on to the next one. But when I press Ctrl+c, it kills the whole for loop.



I guess what I need is either a way to end the current traceroute, or to send the loop a continue.



This question and this one are doing a similar thing, but in more complicated situations. Is there a reasonable way to do this when just running stuff from the prompt?







share|improve this question























    up vote
    0
    down vote

    favorite












    I'm running a loop like this:



    for ip in 10.0.0.1 10.0.0.2 10.0.0.3; do traceroute $ip; done


    I want to be able to kill the current traceroute when it gets boring (and before its 30-hop max), and move on to the next one. But when I press Ctrl+c, it kills the whole for loop.



    I guess what I need is either a way to end the current traceroute, or to send the loop a continue.



    This question and this one are doing a similar thing, but in more complicated situations. Is there a reasonable way to do this when just running stuff from the prompt?







    share|improve this question





















      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      I'm running a loop like this:



      for ip in 10.0.0.1 10.0.0.2 10.0.0.3; do traceroute $ip; done


      I want to be able to kill the current traceroute when it gets boring (and before its 30-hop max), and move on to the next one. But when I press Ctrl+c, it kills the whole for loop.



      I guess what I need is either a way to end the current traceroute, or to send the loop a continue.



      This question and this one are doing a similar thing, but in more complicated situations. Is there a reasonable way to do this when just running stuff from the prompt?







      share|improve this question











      I'm running a loop like this:



      for ip in 10.0.0.1 10.0.0.2 10.0.0.3; do traceroute $ip; done


      I want to be able to kill the current traceroute when it gets boring (and before its 30-hop max), and move on to the next one. But when I press Ctrl+c, it kills the whole for loop.



      I guess what I need is either a way to end the current traceroute, or to send the loop a continue.



      This question and this one are doing a similar thing, but in more complicated situations. Is there a reasonable way to do this when just running stuff from the prompt?









      share|improve this question










      share|improve this question




      share|improve this question









      asked Jun 26 at 0:22









      P1h3r1e3d13

      1153




      1153




















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          2
          down vote



          accepted










          Use trap:



          trap "echo ctr+c pressed" INT TERM;for ip in 10.0.0.1 10.0.0.2 10.0.0.3; do traceroute $ip; done





          share|improve this answer





















          • Ah, that does just what I wanted! The link is useful, but can you explain how it works here?
            – P1h3r1e3d13
            Jun 26 at 0:45










          • Read the fine manual or use google. There are a tons of paper about this.
            – Ipor Sircer
            Jun 26 at 0:58










          • I do appreciate the answer. Just trying to encourage the "Provide context for links" advice from unix.stackexchange.com/help/how-to-answer
            – P1h3r1e3d13
            Jun 26 at 4:51










          Your Answer







          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "106"
          ;
          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',
          convertImagesToLinks: false,
          noModals: false,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );








           

          draft saved


          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f451885%2fbash-stop-a-command-within-a-loop-but-continue-the-loop%23new-answer', 'question_page');

          );

          Post as a guest






























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          2
          down vote



          accepted










          Use trap:



          trap "echo ctr+c pressed" INT TERM;for ip in 10.0.0.1 10.0.0.2 10.0.0.3; do traceroute $ip; done





          share|improve this answer





















          • Ah, that does just what I wanted! The link is useful, but can you explain how it works here?
            – P1h3r1e3d13
            Jun 26 at 0:45










          • Read the fine manual or use google. There are a tons of paper about this.
            – Ipor Sircer
            Jun 26 at 0:58










          • I do appreciate the answer. Just trying to encourage the "Provide context for links" advice from unix.stackexchange.com/help/how-to-answer
            – P1h3r1e3d13
            Jun 26 at 4:51














          up vote
          2
          down vote



          accepted










          Use trap:



          trap "echo ctr+c pressed" INT TERM;for ip in 10.0.0.1 10.0.0.2 10.0.0.3; do traceroute $ip; done





          share|improve this answer





















          • Ah, that does just what I wanted! The link is useful, but can you explain how it works here?
            – P1h3r1e3d13
            Jun 26 at 0:45










          • Read the fine manual or use google. There are a tons of paper about this.
            – Ipor Sircer
            Jun 26 at 0:58










          • I do appreciate the answer. Just trying to encourage the "Provide context for links" advice from unix.stackexchange.com/help/how-to-answer
            – P1h3r1e3d13
            Jun 26 at 4:51












          up vote
          2
          down vote



          accepted







          up vote
          2
          down vote



          accepted






          Use trap:



          trap "echo ctr+c pressed" INT TERM;for ip in 10.0.0.1 10.0.0.2 10.0.0.3; do traceroute $ip; done





          share|improve this answer













          Use trap:



          trap "echo ctr+c pressed" INT TERM;for ip in 10.0.0.1 10.0.0.2 10.0.0.3; do traceroute $ip; done






          share|improve this answer













          share|improve this answer



          share|improve this answer











          answered Jun 26 at 0:32









          Ipor Sircer

          8,6281920




          8,6281920











          • Ah, that does just what I wanted! The link is useful, but can you explain how it works here?
            – P1h3r1e3d13
            Jun 26 at 0:45










          • Read the fine manual or use google. There are a tons of paper about this.
            – Ipor Sircer
            Jun 26 at 0:58










          • I do appreciate the answer. Just trying to encourage the "Provide context for links" advice from unix.stackexchange.com/help/how-to-answer
            – P1h3r1e3d13
            Jun 26 at 4:51
















          • Ah, that does just what I wanted! The link is useful, but can you explain how it works here?
            – P1h3r1e3d13
            Jun 26 at 0:45










          • Read the fine manual or use google. There are a tons of paper about this.
            – Ipor Sircer
            Jun 26 at 0:58










          • I do appreciate the answer. Just trying to encourage the "Provide context for links" advice from unix.stackexchange.com/help/how-to-answer
            – P1h3r1e3d13
            Jun 26 at 4:51















          Ah, that does just what I wanted! The link is useful, but can you explain how it works here?
          – P1h3r1e3d13
          Jun 26 at 0:45




          Ah, that does just what I wanted! The link is useful, but can you explain how it works here?
          – P1h3r1e3d13
          Jun 26 at 0:45












          Read the fine manual or use google. There are a tons of paper about this.
          – Ipor Sircer
          Jun 26 at 0:58




          Read the fine manual or use google. There are a tons of paper about this.
          – Ipor Sircer
          Jun 26 at 0:58












          I do appreciate the answer. Just trying to encourage the "Provide context for links" advice from unix.stackexchange.com/help/how-to-answer
          – P1h3r1e3d13
          Jun 26 at 4:51




          I do appreciate the answer. Just trying to encourage the "Provide context for links" advice from unix.stackexchange.com/help/how-to-answer
          – P1h3r1e3d13
          Jun 26 at 4:51












           

          draft saved


          draft discarded


























           


          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f451885%2fbash-stop-a-command-within-a-loop-but-continue-the-loop%23new-answer', 'question_page');

          );

          Post as a guest













































































          Popular posts from this blog

          How to check contact read email or not when send email to Individual?

          Bahrain

          Postfix configuration issue with fips on centos 7; mailgun relay