Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 9 May 2014 06:42:45 +0000
From:      "Ivailo A. Tanusheff" <ITanusheff@postbank.bg>
To:        "Rick Miller" <vmiller@hostileadmin.com>, "FreeBSD Questions" <freebsd-questions@freebsd.org>
Subject:   RE: Bourne variable unset outside while()
Message-ID:  <1422065A4E115F409E22C1EC9EDAFBA456552E@sofdc01exc02.postbank.bg>
In-Reply-To: <CAHzLAVFhyPtkWCj1uj0aq0AusfrWL55UUn-mkxiyzUus7x4vdA@mail.gmail.com>
References:  <CAHzLAVFhyPtkWCj1uj0aq0AusfrWL55UUn-mkxiyzUus7x4vdA@mail.gmail.com>

next in thread | previous in thread | raw e-mail | index | archive | help
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.



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?1422065A4E115F409E22C1EC9EDAFBA456552E>