Path: utzoo!utgpu!news-server.csri.toronto.edu!bonnie.concordia.ca!nstn.ns.ca!wrdis01!mips!sdd.hp.com!elroy.jpl.nasa.gov!decwrl!pa.dec.com!nntpd.lkg.dec.com!engage!ynotme.enet.dec.com!wallace From: wallace@ynotme.enet.dec.com (Ray Wallace) Newsgroups: comp.unix.shell Subject: Re: cat, pipes, and filters Message-ID: <1991May31.204314.27493@engage.pko.dec.com> Date: 31 May 91 20:32:07 GMT Sender: newsdaemon@engage.pko.dec.com (USENET News Daemon) Organization: Digital Equipment Corporation Lines: 22 In article <1991May31.165446.1530@progress.com>, root@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@oldtmr.enet.dec.com (UUCP) ...!decwrl!oldtmr.enet!wallace (INTERNET) wallace%oldtmr.enet@decwrl.dec.com ---