Date: Sun, 23 Dec 2012 16:52:08 +0100 From: =?UTF-8?B?76O/IERow6luaW4gSmVhbi1KYWNxdWVz?= <dhenin@gmail.com> To: Polytropon <freebsd@edvax.de> Cc: FreeBSD Global Users Mailing List <freebsd-questions@freebsd.org>, Jack Mc Lauren <jack.mclauren@yahoo.com> Subject: Re: shell script problem Message-ID: <CAL5Cjnx7CdTbAm=LMWDvnoiphQRMKOJKXm7ypVZ3wFrJ7i1g_w@mail.gmail.com> In-Reply-To: <20121223104311.557f3752.freebsd@edvax.de> References: <1356253535.76738.YahooMailClassic@web160101.mail.bf1.yahoo.com> <20121223103434.def7cd9c.freebsd@edvax.de> <20121223104311.557f3752.freebsd@edvax.de>
next in thread | previous in thread | raw e-mail | index | archive | help
2012/12/23 Polytropon <freebsd@edvax.de> > On Sun, 23 Dec 2012 10:34:34 +0100, Polytropon wrote: > > First, the lines with "read" have to be: > > > > cat /foo/bar.txt | while read $LINE1 > > > > cat /foo/bar/foo/bar.txt | while read $LINE2 > > > > Reason: $LINE1 and $LINE2 will be evaluated here, they are "empty > > string", causing "read" to throw an error. > > Excuse me - I made a mistake! Of course those two lines > have to be: > > cat /foo/bar.txt | while read LINE1 > > and > > cat /foo/bar/foo/bar.txt | while read LINE2 > > The $ infront of the variable names have to be removed. > The variable _name_, not its content, has to be provided > to "read" as a parameter. > > The script so far: > > > > #!/bin/sh > > cat foo.txt | while read LINE1 > * echo "Pid Process: " $$* > do > cat bar.txt | while read LINE2 > do > if [ "$LINE1" =3D "$LINE2" ]; then > sw=3D"1" > echo "Current value of sw is : " $sw > *ps -ax |grep bar * > break > fi > done > echo "Value of sw is : " $sw > if [ "$sw" =3D "0" ]; then > echo "DO SOMETHING!" > fi > sw=3D"0" > done > Has you can see, "pipe" make a subshell and sw is lost. Hope this help --------------------------------------------------------- (=C2=B0> Dh=C3=A9nin Jean-Jacques / ) 48, rue de la Justice 78300 Poissy ^^ dhenin@gmail.com ---------------------------------------------------------
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CAL5Cjnx7CdTbAm=LMWDvnoiphQRMKOJKXm7ypVZ3wFrJ7i1g_w>