From owner-freebsd-questions@FreeBSD.ORG Fri May 9 14:45: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 5A70EEFE for ; Fri, 9 May 2014 14:45:56 +0000 (UTC) Received: from mx01.qsc.de (mx01.qsc.de [213.148.129.14]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 1B8D4D00 for ; Fri, 9 May 2014 14:45:55 +0000 (UTC) Received: from r56.edvax.de (port-92-195-108-40.dynamic.qsc.de [92.195.108.40]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mx01.qsc.de (Postfix) with ESMTPS id DD2323CD77; Fri, 9 May 2014 16:45:46 +0200 (CEST) Received: from r56.edvax.de (localhost [127.0.0.1]) by r56.edvax.de (8.14.5/8.14.5) with SMTP id s49Ejkrn002194; Fri, 9 May 2014 16:45:46 +0200 (CEST) (envelope-from freebsd@edvax.de) Date: Fri, 9 May 2014 16:45:46 +0200 From: Polytropon To: "Ivailo A. Tanusheff" Subject: Re: Bourne variable unset outside while() Message-Id: <20140509164546.d10312ee.freebsd@edvax.de> In-Reply-To: <1422065A4E115F409E22C1EC9EDAFBA456552E@sofdc01exc02.postbank.bg> References: <1422065A4E115F409E22C1EC9EDAFBA456552E@sofdc01exc02.postbank.bg> Reply-To: Polytropon 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: Rick Miller , FreeBSD Questions 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 14:45:56 -0000 On Fri, 9 May 2014 06:42:45 +0000, Ivailo A. Tanusheff wrote: > 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. This actually works (and is a good idea to get rid of my suggested `awk ...` call per each line of input). In "here documents", variable expansion can be used. If the input will be coming from a file instead, using < /the/file can be done. #!/bin/sh fs="freebsd-ufs gprootfs 1G freebsd-swap gpswapfs 1G freebsd-ufs gpvarfs 1G" while read -r fstype fslabel fssize; do labels="${labels} ${fslabel}" done << EOF "${fs}" EOF echo "labels = ${labels}" The result is: labels = gprootfs gpswapfs gpvarfs There's a leading space because at the first addition, ${labels} is empty, a space and the 1st entry are then added. The awk approach didn't have that "bug", erm... feature. ;-) -- Polytropon Magdeburg, Germany Happy FreeBSD user since 4.0 Andra moi ennepe, Mousa, ...