help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Help-bash] opposite of 'shift'


From: Dan Douglas
Subject: Re: [Help-bash] opposite of 'shift'
Date: Thu, 16 Feb 2012 20:33:22 -0600
User-agent: KMail/4.7.4 (Linux/3.1.6-pf; KDE/4.7.4; x86_64; ; )

On Thursday, February 16, 2012 06:59:14 PM you wrote:
> On 2/16/12 3:56 PM, Dan Douglas wrote:
> > On Thursday, February 16, 2012 09:35:28 AM Greg Wooledge wrote:
> >> On Thu, Feb 16, 2012 at 08:26:59AM -0600, Dan Douglas wrote:
> >>> You can't. nonlocal positional parameters are inacceessable.
> >> 
> >> parameters.  (I gave two example input arrays.)  Sorry for the
> >> confusion.> 
> > Ah, misinterpreted.
> > 
> > But for arrays, it's almost worse! One of the few possible
> > implementations... It's completely incomprehensible, won't work on
> > sparse arrays, and can only return arrays directly to the scope of the
> > caller (or global).
> 
> I wonder why you didn't take advantage of the address@hidden expansion,
> which would have given you the the list of indices.  That may have
> allowed you to handle sparse arrays, at the cost of using an iterator.
> Of course, you did say it was one possible implementation.

Hi, Just wanted to express (to complement what Greg was talking about) that 
having custom functions do things to arrays is pretty hard due to the obstacle 
of getting everything in and out intact without namerefs.  I suppose to pass 
two or more arrays to a function it's possible to expand  each as args along 
with their lengths and keys via address@hidden everywhere it's called, then 
reconstruct local copies.

I've only seen the ability to pass array names as parameters to be expanded 
later mentioned in one place (buried in the middle of here:  
http://mywiki.wooledge.org/BashFAQ/006 ) and was under the impression it isn't 
officially supported.

>From trial and error I gather that if the value of a parameter ends with an 
array subscript syntax then indirection triggers it to be interpreted as an 
array. Nobody seems to know about this (or if they do, nobody uses it), and 
nobody knows how to get keys knowing only an array name stored in a 
parameter/variable AFAIK.

There are also some oddities with that hack. Parameter expansions which 
normally map across elements when combined with indirection applies to the 
resulting concatenated words:

a=(12 34 56);
set -- 'address@hidden';
printf '<%s> ' "${!1}"; echo;
printf '<%s> ' "${!1#[[:digit:]]}";

<12> <34> <56> 
<2 34 56>

Not quite what I expected but could be right.
-- 
Dan Douglas



reply via email to

[Prev in Thread] Current Thread [Next in Thread]