On Samstag, 10. Mai 2008, Steve Long wrote:
> Matthias Schwarzott wrote:
> > Code may look like this:
> >
> > # get last one of sorted list
> > for t in $(ls -1 /usr/bin/gcc-3*|sort); do
>
> use teh globs, luke ;)
> for t in /usr/bin/gcc-3*; do # will already do this, sorting according to
> LC_COLLATE order (set to C or POSIX [same thing] for ebuild.) There's no
> need to step through every one either:
> t=(/usr/bin/gcc-3*); [EMAIL PROTECTED]: -1}; unset t # get rid of array 
> storage
> (using same var for both, eg [EMAIL PROTECTED]: -1} only sets the first cell; 
> the
> rest of the array is still live. var is a synonym for var[0] in BASH.)
>
> set -- *
> t=${@: -1} # works here as well but dunno if that applies to all sh (the -1
> expansion, not the set.) In any event not needed in BASH since arrays make
> our life so much easier ;)
>
Well, you want it compact, without loops.
Here is it:

set -- /usr/bin/gcc-3*
Get first entry: CC="$1"
Get last entry: eval CC="\${$#}"

Regards
Matthias
-- 
gentoo-dev@lists.gentoo.org mailing list

Reply via email to