alex lupu schrieb:
> 
> ls -R linux-3.3.6 | tee >( grep devices > temp.txt) ; echo $PIPESTATUS
> 
> How can I do a 'grep -m n ' (or similar - with an untimely death)


in your seceond example the second process terminates while the first
(ls) still tries to deliver output to the pipe.




to answer your question:

... tee >( grep -m 5 devices > temp.txt || exit 0 ) ; ...

if 'grep' exits with <>0, terminate the subprocess with 0

but this won't solve the problem:
'ls' seems to delay its output for a while (don't ask me why!). now
there is no more input to 'tee' and it will stop, closing the pipe.
'ls' is not really done, tries to write to the closed pipe and will die
with exitcode 141.


i've seen this quite often in constructs like

while read $X ; do
 ...
done < $( ls something )

i now use

ls something >tempfile
while read $X ; do
  ...
done <tempfile



btw: $PIPESTATUS is an ARRAY!!

to get all exit codes use

... ; echo ${PIPESTATUS[@]}


thus your $PIPESTATUS will be ${PIPESTATUS[0]} the exitcode from ls
which exits with 141 whenever the output is piped and the pipe
terminates while ls still writes to the pipe.




have a look at

http://tldp.org/LDP/abs/html/internalvariables.html

and search for PIPESTATUS




tobias

-- 
http://linuxfromscratch.org/mailman/listinfo/blfs-support
FAQ: http://www.linuxfromscratch.org/blfs/faq.html
Unsubscribe: See the above information page

Reply via email to