To all the grep aficionados out there. [I thought of LFS but this is a little too heavy. Chat, it ain't either.]
I've been baffled about something around this grep command [/]$ ls -R linux-3.3.6 | tee >(wc -l) >(grep devices > temp.txt) ; \ echo $PIPESTATUS First, let me deconstruct the above: 1. ls -R linux-3.3.6 Strictly a silly command and directory that would give me about a substantial time of output on the console. 2. >(wc -l) Process substitution. 2.1. 'wc -l' - a silly and innocuous command to do something semi-useful. Note: Just to show that there's no problem with multiple Tee's here, in case the user wants a log or something. This command works just fine, too: ls -R linux-3.3.6 | tee >( grep devices > temp.txt) ; echo $PIPESTATUS 3. >(grep devices > temp.txt) The second process substitution. This one is at the center of bafflement. 3.1. grep devices I chose a word, "devices", which was guaranteed to exist in a large amount in the output of the 'ls' command. Can be anything, of course. 3.2. > temp.txt A redirection of grep's output to a file to pretend I'm interested in something. 4. echo $PIPESTATUS To show some exit results. Gets more interesting in a short while. --------------------------------------------------------- So far so good. FWIW (not terribly interesting yet), I get this after running the command ... 10 secs of lines kvm_main.c last 'ls' file 45096 output of 'wc -l' 0 value of $PIPESTATUS - Now the FRUSTRATION If instead of 'grep word' I use 'grep -m n word', where n is say, 1 or 10, i.e., don't grep me more than one or ten hits respectively - give up after that, I get: ... 2 secs of scrolled file lines dma.c last 'ls' file seen when grep cut off gpiomu2340 a chopped up file name + the wc lines seen at that time 141 value of $PIPESTATUS (based on grep exiting, I suppose) - Now the QUESTION How can I do a 'grep -m n ' (or similar - with an untimely death) while allowing the main process (the listing output, in this case.) to continue to its _natural_ demise? BTW, I did try subprocesses, with little success. Notes: The 'ls' could simulate a lengthy download (a 'git', say). I need the 'grep -m n "..." ' just to see if I have a "..." somewhere in the stream. - Now the PRIZE The winner definitely deserves a >16-oz cup of sugary soda. Note: ">16-oz" is not a process substitution (obviously, no parenthesis). Thanks, -- Alex -- http://linuxfromscratch.org/mailman/listinfo/blfs-support FAQ: http://www.linuxfromscratch.org/blfs/faq.html Unsubscribe: See the above information page