cat, pipes, and filters

Ray Wallace wallace at ynotme.enet.dec.com
Sat Jun 1 06:32:07 AEST 1991


In article <1991May31.165446.1530 at progress.com>, root at progress.COM (Root of all Evil) writes...
>   I've got a question regarding the way cat behaves in a pipeline.
> 
>   cat $FILE | sed s/"$ENTRY"/"$NEWENTRY"/ > $FILE
>Both command produce identical results: $FILE is truncated to 0-length.
One of the first things the shell does when parsing the line, is to handle I/O
redirection. So before any of the commands are executed the ">$FILE" part of
the line causes the shell to create an empty file which just happens to be
the file that you are trying to read (cat).

>   Any enlightenment would be appreciated.  Also, if you can think of
>a better way to do the same thing (short of using perl), please let
  cat $FILE | sed s/"$ENTRY"/"$NEWENTRY"/ > ${FILE}.new ; mv ${FILE}.new $FILE
is a different way, not neccessarily a better way.

---
Ray Wallace		
		(INTERNET,UUCP) wallace at oldtmr.enet.dec.com
		(UUCP)		...!decwrl!oldtmr.enet!wallace
		(INTERNET)	wallace%oldtmr.enet at decwrl.dec.com
---



More information about the Comp.unix.shell mailing list