Mailing List Archive
tlug.jp Mailing List tlug archive tlug Mailing List Archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]Re: [tlug] Bash looping issue
- Date: Wed, 13 Oct 2010 01:37:08 +0900
- From: Romeo Theriault <romeo.theriault@example.com>
- Subject: Re: [tlug] Bash looping issue
- References: <201010121014.06546.daniel.ramaley@example.com>
On Wed, Oct 13, 2010 at 00:14, Daniel A. Ramaley <daniel.ramaley@example.com> wrote:Hello. In the example script below, i define an associative array and
then make a copy of it using a loop to copy each key/value pair. It
seems to work quite nicely... within the loop. Once outside the loop,
the copied array loses its data. The bizarre thing is that if i switch
the loop construct from a "while" to a "for", it works. I'd really like
to use the "while" loop, however, so that in more complicated scripts i
can process the keys in sorted order. (This would be useful, for
example, in building a sorted list of the keys of an associative array.)
I've pasted my sample script and the output below. Any ideas?
Looks like bash is starting the while-read loop in a subshell so you're losing your variable assignments when the subshell exits. This page talks about a few ways around this:
--
Romeo Theriault
- Follow-Ups:
- Re: [tlug] Bash looping issue
- From: Romeo Theriault
- Re: [tlug] Bash looping issue [SOLVED]
- From: Daniel A. Ramaley
- References:
- [tlug] Bash looping issue
- From: Daniel A. Ramaley
Home | Main Index | Thread Index
- Prev by Date: Re: [tlug] Bash looping issue
- Next by Date: Re: [tlug] Network annoyingly not starting on boot [SOLVED]
- Previous by thread: [tlug] Bash looping issue
- Next by thread: Re: [tlug] Bash looping issue
- Index(es):
Home Page Mailing List Linux and Japan TLUG Members Links