I have 2 related Doubts about Bash.
tail -f SomeFile | wc, a fictitious command-line, where
tail is used to simulate a command (C1) which runs for a long time, with some output from time to time, and
wc is used to simulate a command (C2) which processes that output when C1 finishes. After waiting for a long time (longer than usual) I want to see what output has been generated till now, so I want C1 to terminate. But pressing Ctrl-C will kill this whole pipeline. How can I kill only C1 ( or even a component of C1, if that is itself a compound command ) ?
If C1 had been looping over many files and grepping some text, but one file was from some hung nfs server, then I want to kill only that grep process.
(for F in A B C D E ; do grep sometext $F ; done) | wc
Here Ctrl-C will kill the whole command-line, but I want to kill only the currently running (or hung) process and continue with remaining files.
One solution I have, is to open a new connection, get the ps output, and "kill" it. I was wondering if there was a solution from Bash itself, such that some strange key-combination kills only the current process ?
(Q2) While trying to make examples for this question, I made this command-line,Here, where if I press Ctrl-C, I get an extra line of output, like this:
# echo `ping 127.0.0.1` | wc ^C #
When backticks (``) are not used, the extra line is not there:
# tail -f SomeFile | wc ^C #
Am I correct in thinking that since backticks (``) are handled by bash itself and, when the sub-process is killed, it is still considered as "empty output", so that is printed as the extra line ?