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

Re: OT: How to list all but the last item



On Mon, Sep 18, 2006 at 06:39:59PM +0200, Meino Christian Cramer wrote:
> Hi,
> 
>  may be this is a very stupid question...and may be I am blind...
>  But...
> 
>  I want to contruct a loop like
> 
>  for i in `<cmd>`
>  do
>    <do something> ${i}
>  done
> 
>  and <cmd> should return a list of items matched by a regexp
>  or another kind of qualifier and skipping the last item.
> 
>  Example:
> 
>  ls -rtlc * | <???what???>
> 
>  would return every item in a directory exept the newest one.

-c is to sort of the file change-status time. You want file
modification time, it's ls -rtl.

And it should be

ls -rtl | ...

Or

ls -rtld -- * | ...

>  Is there any way to accomplish with something fitting in on
>  a commandline???

ls -tl | tail +2

ls -trl | sed '$d'

Also:

ls -trld -- *(om[2,-1])

Also:

IFS=$'\n\n'
lines=( $(cmd) )
for line in "${(@)lines[1,-2]}"; do ...; done

-- 
Stéphane



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