From owner-freebsd-questions@FreeBSD.ORG Sun Dec 23 09:43:10 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 CE369C8F for ; Sun, 23 Dec 2012 09:43:10 +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 871588FC15 for ; Sun, 23 Dec 2012 09:43:10 +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 73AA7276C9; Sun, 23 Dec 2012 10:43:09 +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 qBN9hBBl002969; Sun, 23 Dec 2012 10:43:11 +0100 (CET) (envelope-from freebsd@edvax.de) Date: Sun, 23 Dec 2012 10:43:11 +0100 From: Polytropon To: Jack Mc Lauren Subject: Re: shell script problem Message-Id: <20121223104311.557f3752.freebsd@edvax.de> In-Reply-To: <20121223103434.def7cd9c.freebsd@edvax.de> References: <1356253535.76738.YahooMailClassic@web160101.mail.bf1.yahoo.com> <20121223103434.def7cd9c.freebsd@edvax.de> 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=US-ASCII Content-Transfer-Encoding: 7bit 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:43:10 -0000 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 do cat bar.txt | while read LINE2 do if [ "$LINE1" = "$LINE2" ]; then sw="1" echo "Current value of sw is : " $sw break fi done echo "Value of sw is : " $sw if [ "$sw" = "0" ]; then echo "DO SOMETHING!" fi sw="0" done -- Polytropon Magdeburg, Germany Happy FreeBSD user since 4.0 Andra moi ennepe, Mousa, ...