From owner-freebsd-questions@FreeBSD.ORG Thu May 8 18:48:23 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 BB54D4C7 for ; Thu, 8 May 2014 18:48:23 +0000 (UTC) Received: from mail-ie0-x22d.google.com (mail-ie0-x22d.google.com [IPv6:2607:f8b0:4001:c03::22d]) (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 8B6833B1 for ; Thu, 8 May 2014 18:48:23 +0000 (UTC) Received: by mail-ie0-f173.google.com with SMTP id rp18so3027780iec.4 for ; Thu, 08 May 2014 11:48:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:date:message-id:subject:from:to:content-type; bh=+1hMBsst4LZ/t5+gTkoga0hWCUsjCvUZU1IN3S3YA6o=; b=Uu8H23HlIBanhV9dwimrzz9v4VSs6C9ndWbLaR1Y8qE8fAqt/kNyoXLCDjAMW/OpFA Yk5nwX2cQnkuvnxZEtt1wO6Sjig4j8UD1LYXPxGp55zj/kLZDRREQho8BFxMlHAGSRJN 3VEk9ILLsltReJOZhxhkBIbqhxXwFUT1Rf0CJ2u+RVlaW3J2M6HG2JsULzhzvy49bkrN vREBeI2uL9mXE/ED/BPjw3hhqpHQsLyDWMfWlK0jyjDQp2KtdR71P6jz/+jyWy464QJF PzhWp2hHcoVk2Q2AblgV8ke3T/Ch57X0bxQZZSUCPxKELuL2JWOvTiUXOs30mfh28Tli LtmA== MIME-Version: 1.0 X-Received: by 10.50.138.72 with SMTP id qo8mr11473543igb.26.1399574902943; Thu, 08 May 2014 11:48:22 -0700 (PDT) Sender: vrwmiller@gmail.com Received: by 10.64.235.212 with HTTP; Thu, 8 May 2014 11:48:22 -0700 (PDT) Date: Thu, 8 May 2014 14:48:22 -0400 X-Google-Sender-Auth: O-GMhJrhK4Ow8zlm2yZB7aG-7nU Message-ID: Subject: Bourne variable unset outside while() From: Rick Miller To: FreeBSD Questions Content-Type: text/plain; charset=UTF-8 X-Content-Filtered-By: Mailman/MimeDel 2.1.18 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: Thu, 08 May 2014 18:48:23 -0000 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="freebsd-ufs gprootfs 1G freebsd-swap gpswapfs 1G freebsd-ufs gpvarfs 1G"; echo "${fs}" | while read -r fstype fslabel fssize; do labels="${labels} ${fslabel}"; echo "${labels}"; done echo -e "\nlabels = ${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