Re: Indirect access to variables, including arrays (was Re: Compare 2 arrays.)

2012-06-07 Thread Bill Gradwohl
On Thu, Jun 7, 2012 at 1:01 AM, Pierre Gaston wrote: > Fwiw here is a robust and simple solution for in_: > > _in () { > local e t > t="${2:?}[@]"; > for e in "${!t}"; do [[ $1 = "$e" ]] && return 0;done > return 1; > } > > The following won't have a name space collision with the 'e' variable

Re: Indirect access to variables, including arrays (was Re: Compare 2 arrays.)

2012-06-07 Thread Pierre Gaston
On Thu, Jun 7, 2012 at 12:27 PM, Dan Douglas wrote: > On Thursday, June 07, 2012 10:01:51 AM Pierre Gaston wrote: >> On Thu, Jun 7, 2012 at 6:07 AM, Linda Walsh wrote: >> >(no I haven't made it space/bracket...whatever proof...just a bit >> > more work) >> >> It's not just "a bit more work", ther

Re: Indirect access to variables, including arrays (was Re: Compare 2 arrays.)

2012-06-07 Thread Dan Douglas
On Thursday, June 07, 2012 10:01:51 AM Pierre Gaston wrote: > On Thu, Jun 7, 2012 at 6:07 AM, Linda Walsh wrote: > >(no I haven't made it space/bracket...whatever proof...just a bit > > more work) > > It's not just "a bit more work", there are many workarounds but it's not > really possible to ma

Re: Indirect access to variables, including arrays (was Re: Compare 2 arrays.)

2012-06-07 Thread Pierre Gaston
On Thu, Jun 7, 2012 at 6:07 AM, Linda Walsh wrote: >(no I haven't made it space/bracket...whatever proof...just a bit > more work) It's not just "a bit more work", there are many workarounds but it's not really possible to make a really robust generic solution for assignment, and in the end it ju

Re: Indirect access to variables, including arrays (was Re: Compare 2 arrays.)

2012-06-06 Thread Pierre Gaston
On Thu, Jun 7, 2012 at 6:07 AM, Linda Walsh wrote: > > > Greg Wooledge wrote: >> >> The only Bourne-family shell that can manipulate arrays whose names are >> passed to a function is ksh93, with its "nameref" command.  Bash has >> nothing analogous to that yet. > > = > > I don't unders

Indirect access to variables, including arrays (was Re: Compare 2 arrays.)

2012-06-06 Thread Linda Walsh
Greg Wooledge wrote: The only Bourne-family shell that can manipulate arrays whose names are passed to a function is ksh93, with its "nameref" command. Bash has nothing analogous to that yet. = I don't understand. Are you saying that ${!nameofvar} isnt' supported? I need a fun

Re: Compare 2 arrays.

2012-05-31 Thread Chet Ramey
On 5/30/12 12:14 PM, Bill Gradwohl wrote: > Admittedly, bash doesn't go out of its way to highlight this technique, but > it does work. > > What say you Chet? Bug or feature? There is no middle ground. Sure, there is. It's not explicitly documented, so the behavior is undefined. You can read t

Re: Compare 2 arrays.

2012-05-30 Thread Dan Douglas
On Wed, May 30, 2012 at 4:57 PM, Greg Wooledge wrote: > > On Wed, May 30, 2012 at 10:14:42AM -0600, Bill Gradwohl wrote: > > What say you Chet? Bug or feature? There is no middle ground. > > That's unrealistic.  There are plenty of things that occupy that middle > ground -- unexpected program beha

Re: Compare 2 arrays.

2012-05-30 Thread Bill Gradwohl
On Wed, May 30, 2012 at 10:57 AM, Greg Wooledge wrote: > There are plenty of things that occupy that middle > ground -- unexpected program behaviors. The programmer can never > anticipate *every* input sequence that users will throw at the software, > so some of them may cause surprises. > > Tru

Re: Compare 2 arrays.

2012-05-30 Thread Greg Wooledge
On Wed, May 30, 2012 at 10:14:42AM -0600, Bill Gradwohl wrote: > What say you Chet? Bug or feature? There is no middle ground. That's unrealistic. There are plenty of things that occupy that middle ground -- unexpected program behaviors. The programmer can never anticipate *every* input sequence

Re: Compare 2 arrays.

2012-05-30 Thread Bill Gradwohl
On Wed, May 30, 2012 at 6:33 AM, Greg Wooledge wrote: > > Hacks like this are precisely why I stress that such functions *should > not* be written in bash. If you want to compare two arrays, use a loop, > without wrapping a function around it. That way you have access to the > arrays directly,

Re: Compare 2 arrays.

2012-05-30 Thread Greg Wooledge
On Tue, May 29, 2012 at 09:25:02PM -0600, Bill Gradwohl wrote: > I have no idea what the wget's are supposed to be doing, but here's a > function that will compare 2 foreign arrays and return true 0 or false 1. > > compareForeignArrays(){ >## $1 and $2 are the names of the arrays to compare. >

Re: Compare 2 arrays.

2012-05-29 Thread Bill Gradwohl
I have no idea what the wget's are supposed to be doing, but here's a function that will compare 2 foreign arrays and return true 0 or false 1. compareForeignArrays(){ ## $1 and $2 are the names of the arrays to compare. ## These are characters strings. local intermediary local sub

Re: Compare 2 arrays.

2012-05-29 Thread Quinn Fissler
See any problem here? #!/bin/bash # [PL] Porownuje dwie tablice, zwraca prawde/falsz. set -x A=( "$1" ) B=( "$2" ) EQUAL=0 if [ ${#A[@]} -eq ${#B[@]} ]; then for id in `seq 0 2 $[ ${#A[@]} - 2 ]`; do if [ "${A[ $id ]}" == "${B[ $id ]}" ]; then EQUAL=1 else EQUAL=0 break fi done fi echo $