Re: Doc-bug Bash manpage:
Seems like this a bug in how 'groff' is configured to display various characters. Sorry the waste of space. Linda Walsh wrote: In my bash package: rpm -qi bash Name : bash Relocations: (not relocatable) Version : 4.1 Vendor: openSUSE Release : 20.25.1 Build Date: Sun 27 Feb 2011 05:51:30 AM PST Install Date: Sun 22 May 2011 01:28:49 PM PDT Build Host: build31 ... in the 'bash' manpage, under the 'set' option, under the "-e" option, there is a paragraph that starts: "Exit immediately if a pipeline (which may consist of a single simple command), a subshell command enclosed in parentheses,..." Later on, there is text: " part of any command executed in a && or ⎪⎪ list ^^ except the command following the final && or ⎪⎪, any ^^ command in a pipeline but the last," The above statement is in error. The unicode character, U+023AA, "Bracket Extension", is not a valid bash operator. read x<<<"$(echo -n "⎪"|hexdump -e '/1 "%02.2x"')" echo $x e28eaa ubytes_to_utf8 $x U+023AA ^^ not the same as "|" (though they may display the same, one knows when one cuts & pastes, or is viewing on a screen that only supports the common ascii characters...), and 'bracket extension' ain't one of them (or I wouldn't have noticed ;-/ ). Fortunately or unfortunately, some of don't work w/terms that display such as vertical bar, but as an empty square (no character mapped). In my bash package: rpm -qi bash Name : bash Relocations: (not relocatable) Version : 4.1 Vendor: openSUSE Release : 20.25.1 Build Date: Sun 27 Feb 2011 05:51:30 AM PST Install Date: Sun 22 May 2011 01:28:49 PM PDT Build Host: build31 ... in the 'bash' manpage, under the 'set' option, under the "-e" option, there is a paragraph that starts: "Exit immediately if a pipeline (which may consist of a single simple command), a subshell command enclosed in parentheses,..." Later on, there is text: " part of any command executed in a && or ⎪⎪ list ^^ except the command following the final && or ⎪⎪, any ^^ command in a pipeline but the last," The above statement is in error. The unicode character, U+023AA, "Bracket Extension", is not a valid bash operator. read x<<<"$(echo -n "⎪"|hexdump -e '/1 "%02.2x"')" echo $x e28eaa ubytes_to_utf8 $x U+023AA ^^ not the same as "|" (though they may display the same, one knows when one cuts & pastes, or is viewing on a screen that only supports the common ascii characters...), and 'bracket extension' ain't one of them (or I wouldn't have noticed ;-/ ). Fortunately or unfortunately, some of don't work w/terms that display such as vertical bar, but as an empty square (no character mapped).
Syntax Question...
I want to have an array of 'names'. given a name, "X", I had a prefix, _p_, so have _p_X, I want to access / manipulate it as an array. so given I pass in a name in a var, I have to use 'indirect' syntax: ${!name} But that doesn't seem to play well with array syntax: ${#${!name}[*]} bash: ${#${!name}[*]}: bad substitution What syntax would I use for this?
Re: Syntax Question...
On Sat, Aug 13, 2011 at 23:41, Linda Walsh 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[*]}")
Re: Syntax Question...
On Sat, Aug 13, 2011 at 6:41 PM, Linda Walsh wrote: > > > > I want to have an array of 'names'. > > given a name, "X", I had a prefix, _p_, so have _p_X, > I want to access / manipulate it as an array. > > so given I pass in a name in a var, I have to use 'indirect' syntax: > > ${!name} > > But that doesn't seem to play well with array syntax: > > ${#${!name}[*]} > bash: ${#${!name}[*]}: bad substitution > > What syntax would I use for this? > > > > Please read BashFAQ/006: http://mywiki.wooledge.org/BashFAQ/006 -- Visit serverfault.com to get your system administration questions answered.
Re: Syntax Question...
On Sun, Aug 14, 2011 at 00:49, Dennis Williamson wrote: > On Sat, Aug 13, 2011 at 6:41 PM, Linda Walsh wrote: >> >> >> >> I want to have an array of 'names'. >> >> given a name, "X", I had a prefix, _p_, so have _p_X, >> I want to access / manipulate it as an array. >> >> so given I pass in a name in a var, I have to use 'indirect' syntax: >> >> ${!name} >> >> But that doesn't seem to play well with array syntax: >> >> ${#${!name}[*]} >> bash: ${#${!name}[*]}: bad substitution >> >> What syntax would I use for this? > > Please read BashFAQ/006: http://mywiki.wooledge.org/BashFAQ/006 "no force in the universe can put NUL bytes into shell strings usefully" Ain't that the goddamn Truth!
Re: Syntax Question...
` Dennis Williamson wrote: On Sat, Aug 13, 2011 at 6:41 PM, Linda Walsh wrote: I have to use 'indirect' syntax: ${!name} But that doesn't seem to play well with array syntax: ${#${!name}[*]}# bash: ${#${!name}[*]}: bad substitution What syntax would I use for this? Please read BashFAQ/006: http://mywiki.wooledge.org/BashFAQ/006 I looked at the pageread every section that was >basic & some basic... nothing about using indirect variables with arrays... (let alone assigning to them).. Still had to use an eval for assigning... Also his page misses a really easy way to do indirect assignment for integer vars: b=1 a=b (($a=23)) echo $b 23 --- It's good to know how to do that w/string-vars in 1 line too (i.e.): ref=line read $ref<<<$(echo "my string") echo $line hi there -- but I wouldn't have known or thought of that w/out reading that page (which only demo's the <
Re: Syntax Question...
` Michael Witten wrote: On Sat, Aug 13, 2011 at 23:41, Linda Walsh 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
Re: Syntax Question...
On Sun, Aug 14, 2011 at 7:51 AM, Linda Walsh wrote: > > > > ` Dennis Williamson wrote: >> >> On Sat, Aug 13, 2011 at 6:41 PM, Linda Walsh wrote: >> >>> >>> I have to use 'indirect' syntax: ${!name} >>> But that doesn't seem to play well with array syntax: >>> ${#${!name}[*]} # bash: ${#${!name}[*]}: bad substitution >>> >>> What syntax would I use for this? >>> >>> >> >> Please read BashFAQ/006: http://mywiki.wooledge.org/BashFAQ/006 >> > > I looked at the pageread every section that was >basic & some basic... > > nothing about using indirect variables with arrays... (let alone assigning > to them).. lies
Re: Syntax Question...
On Sun, Aug 14, 2011 at 04:55, Linda Walsh wrote: > > > > ` Michael Witten wrote: >> >> On Sat, Aug 13, 2011 at 23:41, Linda Walsh 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[*]}"'
Re: Syntax Question...
On Sun, Aug 14, 2011 at 05:56, Michael Witten wrote: > On Sun, Aug 14, 2011 at 04:55, Linda Walsh wrote: >> >> >> >> ` Michael Witten wrote: >>> >>> On Sat, Aug 13, 2011 at 23:41, Linda Walsh 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