From owner-freebsd-questions@FreeBSD.ORG Fri May 9 14:57:06 2014 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id BCB28225 for ; Fri, 9 May 2014 14:57:06 +0000 (UTC) Received: from mail-ie0-x235.google.com (mail-ie0-x235.google.com [IPv6:2607:f8b0:4001:c03::235]) (using TLSv1 with cipher ECDHE-RSA-RC4-SHA (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority G2" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 88FEEE16 for ; Fri, 9 May 2014 14:57:06 +0000 (UTC) Received: by mail-ie0-f181.google.com with SMTP id y20so3915234ier.26 for ; Fri, 09 May 2014 07:57:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:date:message-id:subject :from:to:cc:content-type; bh=Ig7zVlSzAI/VbJp4U+UU2N+LRdgKiLkT+Qsnl8tDoK8=; b=xyHr3UutxjTjW66KufltM6apDckVKx504Bv1P+XHPlsGYDubHhfTkUlz6p8xd13zr4 1+yM3ooFaixm1RAA3yMepEhrtkUmkjR7N48UNd6hqRdyWsW6lRCFJFhOwHme2UJG4LZg PRR4oTxDvIgEvRgPtMy4z88swj3csjnXqReO8aAbO+vQyNXEKY5nQQZKhUDG+mFHV77P YYuYIFAXVsTKH7R1j+W8+Q74wvVMocz5YsEfasTtGRGY2N0OP0rKJXIewIMCz5lKEDCi H3uybEEki5UcxKW0GRogBrBeheiWD9q3+pf3rt6bQQf9l8mHKGXq+b0ZvooDTRFR3t0E KwHg== MIME-Version: 1.0 X-Received: by 10.50.57.17 with SMTP id e17mr10123361igq.10.1399647425383; Fri, 09 May 2014 07:57:05 -0700 (PDT) Sender: vrwmiller@gmail.com Received: by 10.64.34.71 with HTTP; Fri, 9 May 2014 07:57:05 -0700 (PDT) In-Reply-To: <20140509164546.d10312ee.freebsd@edvax.de> References: <1422065A4E115F409E22C1EC9EDAFBA456552E@sofdc01exc02.postbank.bg> <20140509164546.d10312ee.freebsd@edvax.de> Date: Fri, 9 May 2014 10:57:05 -0400 X-Google-Sender-Auth: EmQYmfzQdUnzPD0KC8eaiSFx10U Message-ID: Subject: Re: Bourne variable unset outside while() From: Rick Miller To: Polytropon Content-Type: text/plain; charset=UTF-8 X-Content-Filtered-By: Mailman/MimeDel 2.1.18 Cc: FreeBSD Questions , "Ivailo A. Tanusheff" 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:57:06 -0000 On Fri, May 9, 2014 at 10:45 AM, Polytropon wrote: > 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. ;-) > Yes, this is a more efficient approach. Thanks for providing further input. -- Take care Rick Miller