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

Re: Most Recent File



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?

 # (doesn't handle newlines properly)
 $ ls -Q -- *(-om[1,1])

 # Ugly quoting with backslashes
 $ printf %q *(-om[1,1])

 # Put in variable, quote variable as needed
 $ F="$(echo *(-om[1,1]))"
 $ print -- ${(q)F}

Ciao

Dominik ^_^  ^_^

--

Dominik Vogt




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