From mboxrd@z Thu Jan 1 00:00:00 1970 MIME-Version: 1.0 In-Reply-To: References: Date: Tue, 5 May 2009 07:07:20 -0700 Message-ID: Subject: Re: [9fans] problems with redirection in rc From: Russ Cox To: Fans of the OS Plan 9 from Bell Labs <9fans@9fans.net> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Topicbox-Message-UUID: f57eeb5e-ead4-11e9-9d60-3106f5b1d025 On Tue, May 5, 2009 at 6:29 AM, Rudolf Sykora wro= te: > Hello everyone! > > To get some useful information from a file I write: > > ; for (i in *_r) @{cd $i; echo -n $i^' =C2=A0'; grep total otdit | grep -= v na} > > to get lines from the 'otdit' files in *_r subdirectories with the > word 'total' on them, but no 'na' on them. This works to my liking and > produces sth. like > > 10_r =C2=A0 =C2=A0total =C2=A0 =C2=A0 =C2=A0 =C2=A0: =C2=A0 9.4105E-01 > 11_r =C2=A0 =C2=A0total =C2=A0 =C2=A0 =C2=A0 =C2=A0: =C2=A0 9.3897E-01 > 12_r =C2=A0 =C2=A0total =C2=A0 =C2=A0 =C2=A0 =C2=A0: =C2=A0 9.3685E-01 > 13_r =C2=A0 =C2=A0total =C2=A0 =C2=A0 =C2=A0 =C2=A0: =C2=A0 9.3446E-01 > 14_r =C2=A0 =C2=A0total =C2=A0 =C2=A0 =C2=A0 =C2=A0: =C2=A0 9.3180E-01 > 15_r =C2=A0 =C2=A0total =C2=A0 =C2=A0 =C2=A0 =C2=A0: =C2=A0 9.2890E-01 > 16_r =C2=A0 =C2=A0total =C2=A0 =C2=A0 =C2=A0 =C2=A0: =C2=A0 9.2589E-01 > 17_r =C2=A0 =C2=A0total =C2=A0 =C2=A0 =C2=A0 =C2=A0: =C2=A0 9.2299E-01 > 18_r =C2=A0 =C2=A0total =C2=A0 =C2=A0 =C2=A0 =C2=A0: =C2=A0 9.1860E-01 > ... > 9_r =C2=A0 =C2=A0 total =C2=A0 =C2=A0 =C2=A0 =C2=A0: =C2=A0 9.4317E-01 > > Ok, now I wanted to save this, so I naively appended '> res'. But then > the contents of 'res' was only the last line: > 9_r =C2=A0 =C2=A0 total =C2=A0 =C2=A0 =C2=A0 =C2=A0: =C2=A0 9.4317E-01 In ; for (i in *_r) @{cd $i; echo -n $i^' '; grep total otdit | grep -v na} >= res the >res binds tighter than the for loop, so it runs a separate redirection for each iteration. You need ; { for (i in *_r) @{cd $i; echo -n $i^' '; grep total otdit | grep -v na}} > res > Ok, so I thought '>> res' should be used instead. But then I got sth. lik= e > > =C2=A0];/home/sykora/CALC/doing/tests/9_r/-xeon4 9_r total =C2=A0 =C2=A0 = =C2=A0 =C2=A0: =C2=A0 9.4317E-01 > =C2=A0];/home/sykora/CALC/doing/tests/10_r/-xeon4 10_r =C2=A0 =C2=A0 =C2= =A0 total =C2=A0 =C2=A0 =C2=A0 =C2=A0: =C2=A0 9.4105E-01 > =C2=A0];/home/sykora/CALC/doing/tests/11_r/-xeon4 11_r =C2=A0 =C2=A0 =C2= =A0 total =C2=A0 =C2=A0 =C2=A0 =C2=A0: =C2=A0 9.3897E-01 > =C2=A0];/home/sykora/CALC/doing/tests/12_r/-xeon4 12_r =C2=A0 =C2=A0 =C2= =A0 total =C2=A0 =C2=A0 =C2=A0 =C2=A0: =C2=A0 9.3685E-01 > =C2=A0];/home/sykora/CALC/doing/tests/13_r/-xeon4 13_r =C2=A0 =C2=A0 =C2= =A0 total =C2=A0 =C2=A0 =C2=A0 =C2=A0: =C2=A0 9.3446E-01 > =C2=A0];/home/sykora/CALC/doing/tests/14_r/-xeon4 14_r =C2=A0 =C2=A0 =C2= =A0 total =C2=A0 =C2=A0 =C2=A0 =C2=A0: =C2=A0 9.3180E-01 > =C2=A0];/home/sykora/CALC/doing/tests/15_r/-xeon4 15_r =C2=A0 =C2=A0 =C2= =A0 total =C2=A0 =C2=A0 =C2=A0 =C2=A0: =C2=A0 9.2890E-01 > =C2=A0];/home/sykora/CALC/doing/tests/16_r/-xeon4 16_r =C2=A0 =C2=A0 =C2= =A0 total =C2=A0 =C2=A0 =C2=A0 =C2=A0: =C2=A0 9.2589E-01 , > > which quite surprised me... Can you tell me why this happens? I am runnin= g p9p. You've got the cd implementation from label(1) loaded. In interactive mode, it echos escape codes that are supposed to update the label in your terminal window. Instead it wrote them to the redirected file. I changed label to write to /dev/tty explicitly, which should avoid this problem. Russ