[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Syntax Question...
From: |
Michael Witten |
Subject: |
Re: Syntax Question... |
Date: |
Sun, 14 Aug 2011 06:27:19 +0000 |
On Sun, Aug 14, 2011 at 05:56, Michael Witten <mfwitten@gmail.com> wrote:
> On Sun, Aug 14, 2011 at 04:55, Linda Walsh <bash@tlinx.org> wrote:
>>
>>
>>
>> ` Michael Witten wrote:
>>>
>>> On Sat, Aug 13, 2011 at 23:41, Linda Walsh <bash@tlinx.org> wrote:
>>>
>>>>
>>>> ${#${!name}[*]}
>>>> bash: ${#${!name}[*]}: bad substitution
>>>>
>>>
>>> It's probably what you're trying to avoid, but you'll probably have to
>>> construct and then eval the right code by hand:
>>>
>>> $(eval "echo \${#$name[*]}")
>>>
>>
>> bingo. (sigh)
>>
>> I refactored and am essentially using spaces to store the values in
>> a string, then when I want to check the, I throw them into an array and
>> manip.
>> e.g. (not showing all supporting code)
>>
>> declare -axr _plst_t='_plist_'
>> declare -axl defined_PLists=()
>>
>> add things to the list...
>>
>> plist="$_plst_t$plist"
>> local -al plist_deps=( $plist )
>>
>> {search for value in list, ...]
>>
>> unless ((found)) ; then
>> plist_deps[${#plist_deps[*]}]="$subdep"
>> eval "$plist=( "$plist_deps[@]" )"
>> fi
>
> You want this:
>
> unless ((found)) ; then
> plist_deps+=("$subdep")
> eval $plist='("${plist_deps[@]}")'
> fi
>
> Of course, isn't the variable `plist' supposed to be a reference to
> your *string* variable that holds a space-separated list of items? In
> that case, the last line should be:
>
> IFS=' ' eval $plist='"${a[*]}"'
Woops! That last line should read:
IFS=' ' eval $plist='"${plist_deps[*]}"'
Of course, if each list item is guaranteed never to contain a
word-delimiting character, then the quoting may be simplified.
In the first case:
unless ((found)) ; then
plist_deps+=($subdep)
eval $plist='(${plist_deps[@]})'
fi
and in the second case (where each list item is also guaranteed never
to contain a space character):
unless ((found)) ; then
plist_deps+=($subdep)
IFS=' ' eval $plist=\${plist_deps[*]}
fi
- Syntax Question..., Linda Walsh, 2011/08/13
- Re: Syntax Question..., Dennis Williamson, 2011/08/13
- Re: Syntax Question..., Michael Witten, 2011/08/13
- Re: Syntax Question..., Linda Walsh, 2011/08/14
- Re: Syntax Question..., Pierre Gaston, 2011/08/14
- Re: Syntax Question..., Linda Walsh, 2011/08/14
- Re: Syntax Question..., Pierre Gaston, 2011/08/14
- Re: Syntax Question..., Linda Walsh, 2011/08/14
- Re: Syntax Question..., Dennis Williamson, 2011/08/14
- Re: Syntax Question..., Linda Walsh, 2011/08/14