Re: Is it possible or RFE to expand ranges of *arrays*

2012-04-26 Thread Linda Walsh
John Kearney wrote: echo ${a[@]:1:2} --- Thanks!...I couldn't believe there wasn't some way to do it, but darned if I couldn't think of it or find it for that matter... sigh. Thanks again!

Re: Passing variables by reference conflicts with local

2012-04-26 Thread Greg Wooledge
On Wed, Apr 25, 2012 at 04:46:02PM -0700, Linda Walsh wrote: > I would guess (without looking at the codE), that > when you do a local, it creates another copy of 'var' at the end of an > array. > like var[0][1] > so global is at 0, and local is at 1. I'm pretty sure bash doesn't use a multidimen

Re: Passing variables by reference conflicts with local

2012-04-26 Thread Greg Wooledge
On Mon, Apr 23, 2012 at 04:56:09PM +0800, Clark Wang wrote: > When I revisit this 2 years old thread I don't understand why following > foo() function does not output the global var: > > $ cat foo.sh > var=global > foo() > { > local var=foo > unset var > echo foo: $var > } > bar_unset(

Re: Severe Bash Bug with Arrays

2012-04-26 Thread Maarten Billemont
On 26 Apr 2012, at 01:18, Linda Walsh wrote: > > Ishtar:> echo "${b[*]}" Please note that expanding array elements using [*] is usually NOT what anyone wants. Be careful about recommending it to anyone. "${b[*]}" # This throws away any usefulness of the array by merging all the array elements

Re: Is it possible or RFE to expand ranges of *arrays*

2012-04-26 Thread Maarten Billemont
On 26 Apr 2012, at 06:30, John Kearney wrote: > Am 26.04.2012 06:26, schrieb Linda Walsh: >> I know I can get >> a="abcdef" echo "${a[2:4]}" = cde >> >> how do I do: >> typeset -a a=(apple berry cherry date); then get: >> >> echo ${a[1:2]} = "berry" "cherry" ( non-grouped args) >> >> I tried to

Re: Passing variables by reference conflicts with local

2012-04-26 Thread Bill Gradwohl
I added a bit if code to show some things that I did and did not expect. #!/bin/bash var=global foo() { echo local var=foo unset var echo ${FUNCNAME[@]}: $var displayVar displayVarfoo() { echo ${FUNCNAME[@]}: $var } displayVarfoo } bar_unset() { unset

Re: Severe Bash Bug with Arrays

2012-04-26 Thread Greg Wooledge
On Thu, Apr 26, 2012 at 05:54:27PM +0200, Maarten Billemont wrote: > On 26 Apr 2012, at 01:18, Linda Walsh wrote: > > > > Ishtar:> echo "${b[*]}" > > You should always recommend the "${b[@]}" variant. "${b[*]}" is rarely > useful in the event that your intent is to merge the array into a single

Re: Passing variables by reference conflicts with local

2012-04-26 Thread Greg Wooledge
On Thu, Apr 26, 2012 at 12:02:20PM -0600, Bill Gradwohl wrote: > bar_unset() { > unset var > echo ${FUNCNAME[@]}: $var > displayVar > displayVarbar_unset() { >echo ${FUNCNAME[@]}: $var > } > displayVarbar_unset > echo > newVar=bar_unset > } > When newVar is

Re: Passing variables by reference conflicts with local

2012-04-26 Thread Bill Gradwohl
On Thu, Apr 26, 2012 at 12:49 PM, Greg Wooledge wrote: > I don't see this as a surprise. It's how you return values from functions > in bash. Pick a global variable (r, ret, whatever you want) and stuff the > return value into that. You can even declare your "r" locally somewhere > so that the

Re: Passing variables by reference conflicts with local

2012-04-26 Thread Greg Wooledge
On Thu, Apr 26, 2012 at 01:37:57PM -0600, Bill Gradwohl wrote: > When the child creates a global to pass back information, and then > terminates, the parent had no control over that variables creation and is > now stuck with something in the global name space that via the hierarchy of > calls, it d

protection against accidental massive pastes into the command line

2012-04-26 Thread jidanni
Maybe there should be a limit, MAX_INTERACTIVE_COMMAND_LENGTH on how much can be fed into one bash command line, any more and bash should beep and reject the whole command. Otherwise an innocent middle click, or SHIFT INSERT slip of the fingers could paste an entire book out of the clipboard, into

Re: protection against accidental massive pastes into the command line

2012-04-26 Thread jidanni
This would also save on later having to clean the massive blob out of the history list.

Re: Severe Bash Bug with Arrays

2012-04-26 Thread DJ Mills
On Thu, Apr 26, 2012 at 2:16 PM, Greg Wooledge wrote: > If the goal is to see the contents of an array, I'd use one of these, > depending on how much detail I need: > > printf '<%s> ' "${array[@]}"; echo > > declare -p array > Or i'd use the args function Greg has shown before: args() { printf

Re: [patch] fix building when readline is disabled

2012-04-26 Thread Mike Frysinger
On Tuesday 24 April 2012 15:49:57 Chet Ramey wrote: > On 4/24/12 10:46 AM, Mike Frysinger wrote: > > On Tuesday 24 April 2012 08:23:04 Chet Ramey wrote: > >> On 4/24/12 12:00 AM, Mike Frysinger wrote: > OK, so you've stripped the local readline copy out of the source tree? > >>> > >>> yes > >

Re: protection against accidental massive pastes into the command line

2012-04-26 Thread Allodoxaphobia
On Fri, 27 Apr 2012 04:18:21 +0800, jida...@jidanni.org wrote: > This would also save on later having to clean the massive blob out of > the history list. And, the Murphy's Law case(s) where one of the pasted lines contains a 'legitimate' linux command... Been there -- got a T-shirt. Jonesy

declare -ag with assignment bug

2012-04-26 Thread Joseph Graham
Configuration Information [Automatically generated, do not change]: Machine: mips64el OS: linux-gnu Compiler: mips64el-unknown-linux-gnu-gcc Compilation CFLAGS: -DPROGRAM='bash' -DCONF_HOSTTYPE='mips64el' -DCONF_OSTYPE='linux-gnu' -DCONF_MACHTYPE='mips64el-unknown-linux-gnu' -DCONF_VENDOR='unkno

Re: declare -ag with assignment bug

2012-04-26 Thread Chet Ramey
On 4/26/12 4:50 PM, Joseph Graham wrote: > Bash Version: 4.2 > Patch Level: 24 > Release Status: release > > Description: > Arrays defined in a function with declare -ag are not > available outside the function if an assignment is done with the > declaration, though it works if the assignment is

Re: Passing variables by reference conflicts with local

2012-04-26 Thread Clark Wang
On Fri, Apr 27, 2012 at 02:02, Bill Gradwohl wrote: > > So, if you want to make sure a sub > function can't touch a variable, put another function in between that > localises and then unsets the variable. > Sounds interesting. Will see if I can take advantage of this in future. :) > > > -- > Bi

Re: Passing variables by reference conflicts with local

2012-04-26 Thread Clark Wang
On Fri, Apr 27, 2012 at 02:49, Greg Wooledge wrote: > > I don't see this as a surprise. It's how you return values from functions > in bash. Pick a global variable (r, ret, whatever you want) and stuff the > return value into that. You can even declare your "r" locally somewhere > so that the

Re: Severe Bash Bug with Arrays

2012-04-26 Thread Linda Walsh
Maarten Billemont wrote: On 26 Apr 2012, at 01:18, Linda Walsh wrote: Ishtar:> echo "${b[*]}" Please note that expanding array elements using [*] is usually NOT what anyone wants. --- It was exactly what I wanted for my example to work. Please don't suggest non-working solutions to th

Re: Severe Bash Bug with Arrays

2012-04-26 Thread Mike Frysinger
On Thursday 26 April 2012 23:47:39 Linda Walsh wrote: > Anything else you wanna tell me NEVER/ALWAYS to do? try ALWAYS being polite. but i guess that'll NEVER happen. oh well, thankfully kmail can auto-mute based on sender. -mike signature.asc Description: This is a digitally signed message pa