Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Use of variables in the <x-y> globbing mechanism



On Apr 20, 10:24pm, Henman wrote:
} 
} It would be very useful if  the <x-y> globbing mechanism would work with 
} variables.

It can't do so because <$x-$y> is valid redirection syntax, meaning to
read from file "$x-$y" and write to whatever comes after.  It's rare
enough to have files with digit-digit names that it was deemed OK to
break the redirection rules in that special case, but it would cause
to many problems to generalize it.

} # The from_number and to_number are read in from a list of files to process
}      and injected between a filename pattern's prefix and extension.
} 
}     for file in ${SFNPAT:r}-<${from_number}-${to_number}>.${SFNPAT:e}

Use the {x..y} syntax:

    for file in ${SFNPAT:r}-{${from_number}..${to_number}}.${SFNPAT:e}

This latter expands to the full list of names rather than globbing them,
so it won't skip any missing files, but it will probably work in your
example.

If there may be gaps in the file sequence so you really do need to do
the glob, put the entire expression in a variable like so:

    local slice="<${from_number}-${to_number}>"
    for file in ${SFNPAT:r}-${~slice}.${SFNPAT:e}



Messages sorted by: Reverse Date, Date, Thread, Author