From owner-freebsd-questions@FreeBSD.ORG Fri May 9 06:43:56 2014 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id C33A52E1 for ; Fri, 9 May 2014 06:43:56 +0000 (UTC) Received: from mail.postbank.bg (mx.postbank.bg [195.242.126.253]) by mx1.freebsd.org (Postfix) with ESMTP id 15234D55 for ; Fri, 9 May 2014 06:43:54 +0000 (UTC) Received: from SOFDC01EXC09.postbank.bg ([10.1.129.36] unverified) by mail.postbank.bg over TLS secured channel with Microsoft SMTPSVC(7.5.7601.17514); Fri, 9 May 2014 09:42:29 +0300 Received: from SOFDC01EXCV15.postbank.bg (10.1.129.38) by SOFDC01EXC09.postbank.bg (10.1.129.36) with Microsoft SMTP Server (TLS) id 8.3.159.2; Fri, 9 May 2014 09:42:46 +0300 From: "Ivailo A. Tanusheff" To: "Rick Miller" , "FreeBSD Questions" Subject: RE: Bourne variable unset outside while() Thread-Topic: Bourne variable unset outside while() Thread-Index: AQHPau4c4BW2qtG5PU+/HX4AuNWOB5s3zZmA Content-Class: urn:content-classes:message Importance: normal Priority: normal X-MimeOLE: Produced By Microsoft MimeOLE V6.1.7601.17609 Date: Fri, 9 May 2014 06:42:45 +0000 Message-ID: <1422065A4E115F409E22C1EC9EDAFBA456552E@sofdc01exc02.postbank.bg> References: In-Reply-To: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.1.2.28] Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginalArrivalTime: 09 May 2014 06:42:29.0392 (UTC) FILETIME=[D8FB8900:01CF6B51] X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 09 May 2014 06:43:56 -0000 Hi, I think you can check out this: http://stackoverflow.com/questions/7482510/variable-incrementing-in-bash So I sugest you do the same trick or use different approach - awk or = something like this. Regards, Ivailo Tanusheff -----Original Message----- From: owner-freebsd-questions@freebsd.org = [mailto:owner-freebsd-questions@freebsd.org] On Behalf Of Rick Miller Sent: Thursday, May 08, 2014 9:48 PM To: FreeBSD Questions Subject: Bourne variable unset outside while() Hi all, I have a Bourne shell script that echoes the contents of a data = structure to a while() loop that iterates over the data and is expected = to append a string from the current iteration to a different list. = Inside the while(), it works fine, but echo'ing the list outside the = loop produces empty output. I expect the variable to maintain it's = final state after processing the while(), but it does not appear to be = doing so. /** The script **/ #! /bin/sh -x fs=3D"freebsd-ufs gprootfs 1G freebsd-swap gpswapfs 1G freebsd-ufs gpvarfs 1G"; echo "${fs}" | while read -r fstype fslabel fssize; do labels=3D"${labels} ${fslabel}"; echo "${labels}"; done echo -e "\nlabels =3D ${labels}"; /** End the script **/ The output from this script is at http://pastebin.com/mxNLLWtm This almost appears to be an issue with scope, but I've not encountered = this before, especially in such simple context. I must be missing = something obvious and just looking for feedback to send me off in the = right direction. -- Take care Rick Miller _______________________________________________ freebsd-questions@freebsd.org mailing list = http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to = "freebsd-questions-unsubscribe@freebsd.org" Disclaimer: This communication is confidential. If you are not the intended = recipient, you are hereby notified that any disclosure, copying, = distribution or taking any action in reliance on the contents of this = information is strictly prohibited and may be unlawful. If you have = received this communication by mistake, please notify us immediately by = responding to this email and then delete it from your system. Eurobank Bulgaria AD is not responsible for, nor endorses, any opinion, = recommendation, conclusion, solicitation, offer or agreement or any = information contained in this communication. Eurobank Bulgaria AD cannot accept any responsibility for the accuracy = or completeness of this message as it has been transmitted over a public = network. If you suspect that the message may have been intercepted or = amended, please call the sender.