On Mon, Oct 06, 2014 at 04:04:25PM -0700, Linda Walsh wrote: > Greg Wooledge wrote: > >netdev_pat=... # (and other variable assignments) > >(cd "$sysnet" && > >for ifname in ...; do > > hwaddr=$(<"$ifname"/address) > > act_hw2if[$hwaddr]="$ifname" > > act_if2hw[$ifname]="$hwaddr" > >done) > > Except that either act_hw2if + pair were just assigned to > in the sub process that was meant to isolate the change > of directory from the rest of the program, > OR > we aren't in the right directory when we do the reads.
OK, then use a function to give you an escapable block: declare -A ... create_maps() { cd "$sysnet" || return for ifname in ...; do hwaddr=$(<"$ifname"/address) act_hw2if[$hwaddr]="$ifname" act_hw2if[$ifname]="$hwaddr" done } create_maps > Either way, they code as you have suggested won't work > without overcoming another set of side effects. There are ways to NOT use subshells. I have given you two of those ways now.