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

Re: Most Recent File



Thanks. I had attempted to strip away unnecessary complexity from my problem, but I now see that was a mistake. I have a function, recent:

# Print the names of the most recent files in the specified directory.
# Usage: recent [count [file_pattern]]] [directory]
#               count defaults to 1
#               file_pattern defaults to *
#               directory defaults to the current directory.

local dir=
if [[ $# -gt 2 ]]; then
  if [[ ! -d "$3" ]]; then
    print -u2 "$0: directory \"$3\" does not exist."
    return 1
  fi
  [[ $3 != '.' ]] && dir="$3"/
fi

print -l -- ${dir}${~2:-*}(-om[1,${1:-1}])

So far, so good.  recent 3 ==>

zsh/
Any Given Sunday.mkv
TheEnglishPatient.mkv
BUT ls -ld $( recent 3 ) ==>

/usr/bin/ls: cannot access 'Any': No such file or directory
/usr/bin/ls: cannot access 'Given': No such file or directory
/usr/bin/ls: cannot access 'Sunday.mkv': No such file or directory
-rw-r--r-- 1 acs acs 727146010 Oct 22 15:52 TheEnglishPatient.mkv
drwxr-xr-x 3 acs acs      3488 Oct 23 12:20 zsh/

I would like to make the second example work.  I don't particularly care how the first example looks.  Do I really have to use an external command (like `printf') to make this work?

  - Vin


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