bash - stop a command within a loop but continue the loop
Clash 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?
bash
add a comment |Â
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?
bash
add a comment |Â
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?
bash
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?
bash
asked Jun 26 at 0:22
P1h3r1e3d13
1153
1153
add a comment |Â
add a comment |Â
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
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
add a comment |Â
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
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
add a comment |Â
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
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
add a comment |Â
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
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
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
add a comment |Â
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
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password