[Top][All Lists]

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

Re: [Help-bash] indirection for arrays

From: Steven W. Orr
Subject: Re: [Help-bash] indirection for arrays
Date: Mon, 07 May 2012 09:22:34 -0400
User-agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv: Gecko/20120306 Thunderbird/3.1.20

On 5/7/2012 9:16 AM, Greg Wooledge wrote:
On Mon, May 07, 2012 at 09:12:52AM -0400, Steven W. Orr wrote:
and I can also say stuff like:

typeset -a flist
glob_array flist "$srpms/$dist/elx-lpfc-*_$dist.src.rpm"

How is that better than (or even different from):


Mine is better because it sets and restores nullglob. My flist will be a zero length list if the glob does not match any files.

Here it is if anyone wants it...

# Take pairs of glob patterns and array names and set the array names to the
# resulting glob patterns. If the glob doesn't match then the array is
# left empty.
    typeset pattern
    typeset -i ii
    typeset -a aval
    typeset -i nullglob_status=0
    typeset -r nullglob_reset=su        # Set Unset
    typeset -i nn=0

    (( $# & 1 )) && die 'ERROR: glob_array takes an even number of args'
    shopt -p nullglob > /dev/null
    shopt -s nullglob

    while (( $# ))
        typeset $1
        aval=( $pattern )
        # This should never fail as long as $nn matches passing all of aval.
        # Check anyways for extra credit.
        upvars -a$nn $1 "address@hidden" || die 'ERROR:upvars failed.'
        shift 2
    shopt -${nullglob_reset:$nullglob_status:1} nullglob

Time flies like the wind. Fruit flies like a banana. Stranger things have  .0.
happened but none stranger than this. Does your driver's license say Organ ..0
Donor?Black holes are where God divided by zero. Listen to me! We are all- 000
individuals! What if this weren't a hypothetical question?
steveo at

reply via email to

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