From owner-freebsd-questions@FreeBSD.ORG Sun Dec 23 09:05:36 2012 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id F0A0A95E for ; Sun, 23 Dec 2012 09:05:36 +0000 (UTC) (envelope-from jack.mclauren@yahoo.com) Received: from nm17-vm0.bullet.mail.bf1.yahoo.com (nm17-vm0.bullet.mail.bf1.yahoo.com [98.139.213.157]) by mx1.freebsd.org (Postfix) with ESMTP id 8E2948FC14 for ; Sun, 23 Dec 2012 09:05:36 +0000 (UTC) Received: from [98.139.212.153] by nm17.bullet.mail.bf1.yahoo.com with NNFMP; 23 Dec 2012 09:05:35 -0000 Received: from [98.139.212.203] by tm10.bullet.mail.bf1.yahoo.com with NNFMP; 23 Dec 2012 09:05:35 -0000 Received: from [127.0.0.1] by omp1012.mail.bf1.yahoo.com with NNFMP; 23 Dec 2012 09:05:35 -0000 X-Yahoo-Newman-Property: ymail-3 X-Yahoo-Newman-Id: 571571.63867.bm@omp1012.mail.bf1.yahoo.com Received: (qmail 11803 invoked by uid 60001); 23 Dec 2012 09:05:35 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s1024; t=1356253535; bh=3oFGvvGMtZfV5yZg4D8s5nq4QRiJrQU/Nywg1oNPObE=; h=X-YMail-OSG:Received:X-Rocket-MIMEInfo:X-Mailer:Message-ID:Date:From:Subject:To:MIME-Version:Content-Type; b=pt9ocBuwa0rTVTF4/qFxQ7yWeWSJwgjQFQ3ki7j/FO1XEjPlYVvIUR8Ecx8hihTLSJJS6KeLYqhURXBKI4EGA9+Nl5zpSRhTl4FQlioA7qaarHewo/AIIiJxCmEI0JNGPW+CijqBEBTLjb6ud2JrNaVGg76QomurhcpEz87CYf8= DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.com; h=X-YMail-OSG:Received:X-Rocket-MIMEInfo:X-Mailer:Message-ID:Date:From:Subject:To:MIME-Version:Content-Type; b=ld9VciqDBopJW20oytiGCYjUku20S8o+PbAqYDmvCTuwoqFJ/aVu8ldi0uOllmyOfZ2otzfg/1l+eiJU5w9YeFWO04Z1SV6Y4lK7bB9IuoPUpBn88IrBUwFa08mgoRsFI8Hu4IJmnQgQsr44iK9CHgoSPd5LhY0Ap6kcsreaPlQ=; X-YMail-OSG: Tl9vKKMVM1mUCXgdlHvdY1EfLT8u6LRlqGaC9Gk3q49tw97 xSmnRJCaAjOWckgxY2vAukt2rBp1EKQZYTGPwKBgJIfcN5x_r1q7AKkC4DKk 63eSJfEl0Jb2TzcpXh6kLdksTJvBC8N3wAPr1D4MfcCpbAfngi6lMtF1alW4 12JO3aJBqh_pow8w4_Q60w5JrDJwxowis4JCaGWTY1nBUhQCUCnhQebu9pO5 d6tMI_LjjIXD29rvG5QVuQHYhU3.vrVxLwa0pnQNGUdMc8j9N1SwViEKi.NL oBfJjAHbfB.kAa.6RF9.W.tsYPi.TiEtbbfKhqI2aQ16_5d_Yzgeh4TuGeaF .Ymn4gyw4OM9lmLsGHdtTThqTPUlPslFng2ftPvcBpWSK1kfyxTDDQ1j4X0d SmHeE3qempzuhHcc4dWQftdpQ6uq98ix8ywww7ikO76EREyqeKLRdeHU6C59 G Received: from [89.165.120.140] by web160101.mail.bf1.yahoo.com via HTTP; Sun, 23 Dec 2012 01:05:35 PST X-Rocket-MIMEInfo: 001.001, SGkgYWxsDQpQbGVhc2UgdGFrZSBhIGxvb2sgYXQgdGhlIHNjcmlwdCBiZWxvdyB3aWNoIEkndmUgd3JvdGUgOg0KMS0gY2F0IC9mb28vYmFyLnR4dCB8IHdoaWxlIHJlYWQgJExJTkUxMi0gZG8zLSDCoCDCoGNhdCAvZm9vL2Jhci9mb28vYmFyLnR4dCB8IHdoaWxlIHJlYWQgJExJTkUyNC0gwqAgwqBkb8KgNS0gwqAgwqAgwqAgwqAgaWYgWyAiJExJTkUxIiA9ICIkTElORTIiIF07IHRoZW42LSDCoCDCoCDCoCDCoCDCoCDCoCDCoCBzdz0iMSI3LSDCoCDCoCDCoCDCoCDCoCDCoCDCoCBlY2hvICJDdXJyZW50IHYBMAEBAQE- X-Mailer: YahooMailClassic/15.1.1 YahooMailWebService/0.8.129.483 Message-ID: <1356253535.76738.YahooMailClassic@web160101.mail.bf1.yahoo.com> Date: Sun, 23 Dec 2012 01:05:35 -0800 (PST) From: Jack Mc Lauren Subject: shell script problem To: FreeBSD Global Users Mailing List MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable X-Content-Filtered-By: Mailman/MimeDel 2.1.14 X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 23 Dec 2012 09:05:37 -0000 Hi all Please take a look at the script below wich I've wrote : 1- cat /foo/bar.txt | while read $LINE12- do3- =A0 =A0cat /foo/bar/foo/bar.= txt | while read $LINE24- =A0 =A0do=A05- =A0 =A0 =A0 =A0 if [ "$LINE1" =3D = "$LINE2" ]; then6- =A0 =A0 =A0 =A0 =A0 =A0 =A0 sw=3D"1"7- =A0 =A0 =A0 =A0 = =A0 =A0 =A0 echo "Current value of sw is : " $sw8- =A0 =A0 =A0 =A0 =A0 =A0 = =A0 break9- =A0 =A0 =A0 =A0 fi10- =A0 =A0done11- =A0 =A0echo "Value of sw i= s : " $sw12- =A0 =A0if [ "$sw" =3D "0" ]; then13- =A0 =A0 =A0 =A0 DO SOMETH= ING14- =A0 =A0fi15- =A0 =A0sw=3D"0"16- done =A0 =A0 =A0 =A0 =A0 You probebly guessed what I want to do. But the problem is that when the va= lue of sw sets to 1 (in the first if statement) and the loop breaks , the v= alue of sw is not '1' anymore in " echo "Value of sw is : " $sw " !!! Thanks in advance ... From owner-freebsd-questions@FreeBSD.ORG Sun Dec 23 09:34:39 2012 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 9A83BB94 for ; Sun, 23 Dec 2012 09:34:39 +0000 (UTC) (envelope-from freebsd@edvax.de) Received: from mx02.qsc.de (mx02.qsc.de [213.148.130.14]) by mx1.freebsd.org (Postfix) with ESMTP id 51D248FC0A for ; Sun, 23 Dec 2012 09:34:39 +0000 (UTC) Received: from r56.edvax.de (port-92-195-94-87.dynamic.qsc.de [92.195.94.87]) by mx02.qsc.de (Postfix) with ESMTP id 8B4FF276D5; Sun, 23 Dec 2012 10:34:32 +0100 (CET) Received: from r56.edvax.de (localhost [127.0.0.1]) by r56.edvax.de (8.14.5/8.14.5) with SMTP id qBN9YYFr002893; Sun, 23 Dec 2012 10:34:34 +0100 (CET) (envelope-from freebsd@edvax.de) Date: Sun, 23 Dec 2012 10:34:34 +0100 From: Polytropon To: Jack Mc Lauren Subject: Re: shell script problem Message-Id: <20121223103434.def7cd9c.freebsd@edvax.de> In-Reply-To: <1356253535.76738.YahooMailClassic@web160101.mail.bf1.yahoo.com> References: <1356253535.76738.YahooMailClassic@web160101.mail.bf1.yahoo.com> Organization: EDVAX X-Mailer: Sylpheed 3.1.1 (GTK+ 2.24.5; i386-portbld-freebsd8.2) Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Cc: FreeBSD Global Users Mailing List X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list Reply-To: Polytropon List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 23 Dec 2012 09:34:39 -0000 On Sun, 23 Dec 2012 01:05:35 -0800 (PST), Jack Mc Lauren wrote: > Hi all > Please take a look at the script below wich I've wrote : > 1- cat /foo/bar.txt | while read $LINE12- do3- =A0 =A0cat /foo/bar/foo/ba= r.txt | while read $LINE24- =A0 =A0do=A05- =A0 =A0 =A0 =A0 if [ "$LINE1" = =3D "$LINE2" ]; then6- =A0 =A0 =A0 =A0 =A0 =A0 =A0 sw=3D"1"7- =A0 =A0 =A0 = =A0 =A0 =A0 =A0 echo "Current value of sw is : " $sw8- =A0 =A0 =A0 =A0 =A0 = =A0 =A0 break9- =A0 =A0 =A0 =A0 fi10- =A0 =A0done11- =A0 =A0echo "Value of = sw is : " $sw12- =A0 =A0if [ "$sw" =3D "0" ]; then13- =A0 =A0 =A0 =A0 DO SO= METHING14- =A0 =A0fi15- =A0 =A0sw=3D"0"16- done =A0 =A0 This is totally distorted! Allow me to re-arrange it. cat /foo/bar.txt | while read $LINE1 do cat /foo/bar/foo/bar.txt | while read $LINE2 do if [ "$LINE1" =3D "$LINE2" ]; then sw=3D"1" echo "Current value of sw is : " $sw break fi done echo "Value of sw is : " $sw if [ "$sw" =3D "0" ]; then DO SOMETHING fi sw=3D"0" done 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. =A0 =A0 =A0 > You probebly guessed what I want to do. But the problem is that > when the value of sw sets to 1 (in the first if statement) and > the loop breaks , the value of sw is not '1' anymore in > " echo "Value of sw is : " $sw " !!! > Thanks in advance ... For testing, I've replaced the $sw=3D0 line with an "echo" command. I've created two files foo.txt and bar.txt for test, both have one line in common (3rd line in my example data). If I run the script, I get this output: Value of sw is : <- after 1st line (uninitialized) Value of sw is : 0 <- after 2nd line DO SOMETHING! Current value of sw is : 1 <- after 3nd line (common entry) Value of sw is : 0 <- after 4th line DO SOMETHING! Value of sw is : 0 <- after 5th line DO SOMETHING! It seems that the condition $LINE1=3D$LINE2 properly triggers the "current value" echo command, while all non-common lines trigger the "DO SOMETHING" action. If you indended something else, please elaborate. --=20 Polytropon Magdeburg, Germany Happy FreeBSD user since 4.0 Andra moi ennepe, Mousa, ...