From owner-freebsd-questions@FreeBSD.ORG Sun Dec 23 15:52:54 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 F0485685 for ; Sun, 23 Dec 2012 15:52:54 +0000 (UTC) (envelope-from dhenin@gmail.com) Received: from mail-ie0-f171.google.com (mail-ie0-f171.google.com [209.85.223.171]) by mx1.freebsd.org (Postfix) with ESMTP id AD53B8FC14 for ; Sun, 23 Dec 2012 15:52:54 +0000 (UTC) Received: by mail-ie0-f171.google.com with SMTP id 17so8203236iea.2 for ; Sun, 23 Dec 2012 07:52:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type; bh=uHZvV6rYXdCVZk9/Fpt8sQu9/8nR+5nAaRG0Dj9FegY=; b=Iz2d4xtfnBfdeNMLfetUj+G9VyXNylceKbcKDJ9EwnfvEkrwa6miZF94JPuTjYmXOB d8UbtwTbdwqt4Woh4STpgukdnleZ0vZsTOatyE6d66Ef3n66yviPdwHxcStWeeS5eYw3 0lMFeTgz/eB3FToarUpdM5fE2qrpcGSX+2ADU5reWibnad2Hw3aUmvAVVvxpth53iLGu kQROILl3ABYRxOqsVNXMNuvmuuqD1b/evRCh9aUK3Et6hisNdGA9VwMileRM7NIEdn+b JHrDnBhJ/3HONNJMJ4/oEthHecmm86BPmG4/k5jp/OkGRgItGXK+BF1Oj81ATfKMXq4i ycJw== Received: by 10.50.161.232 with SMTP id xv8mr17791754igb.22.1356277968092; Sun, 23 Dec 2012 07:52:48 -0800 (PST) MIME-Version: 1.0 Received: by 10.64.24.229 with HTTP; Sun, 23 Dec 2012 07:52:08 -0800 (PST) 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> From: =?UTF-8?B?76O/IERow6luaW4gSmVhbi1KYWNxdWVz?= Date: Sun, 23 Dec 2012 16:52:08 +0100 Message-ID: Subject: Re: shell script problem To: Polytropon Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Content-Filtered-By: Mailman/MimeDel 2.1.14 Cc: FreeBSD Global Users Mailing List , Jack Mc Lauren 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 15:52:55 -0000 2012/12/23 Polytropon > 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 ---------------------------------------------------------