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

Re: Most Recent File



On Sat, 2021-10-23 at 17:43 +0100, Dominik Vogt wrote:
> On Sat, Oct 23, 2021 at 12:15:35PM -0400, Vin Shelton wrote:
> > I want to list the most recent file in the current directory.
> >     print -l -- *(-om[1,1])
> > works for ordinary filenames, but does not quote the output appropriately
> > if the filename contains spaces.  How do I quote the expression to
> > accommodate filenames which contain spaces?
> 
>  # Put in variable, quote variable as needed
>  $ F="$(echo *(-om[1,1]))"
>  $ print -- ${(q)F}

An array would be neater since you get globbing for free... it also
extends more naturally if you need multiple files (print -l then handles
those on multiple lines, though there are other ways there).

f=(*(-om[1,1]))
print -l -- ${(q)f}

You get the choice of type of quoting here by changing the (q) to its
various relatives.

pws





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