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

Re: Copy newest file to newest directory



[zzapper: sorry, 1st mail went to you in private.]

zzapper <david@xxxxxxxxxx>:
> Frank Terbeck <ft@xxxxxxxxxxxxxxxxxx>:
> 
> > zzapper <david@xxxxxxxxxx>:
> >> I have some global aliases which call scripts such that I can write
> >> 
> >> > cp NF ND
> >> Where NF copies the newest file to ND the newest directory
> > 
> > [snip]
> > function cpn() {
> >   local nf nd
> >   nf=${1}/*(.om[1]N)
> >   nd=${2}/*(/om[1]N)
> >   [[ -n ${nd} && -n ${nf} ]] && command cp ${nf} ${nd}
> > }
> > [snap]
> > 
> > % cpn /tmp /store
> 
> Frank,
> Looks the business, but not does not work for me

Yeah, that's what happens, if you don't try out what you've posted. :-)

[snip]
function cpn() {
  setopt localoptions
  setopt globassign
  local nf nd
  [[ -z ${1} || -z ${2} ]] && printf 'usage: cpn <fromdir> <todir>\n' && return 1
  nf=${1}/*(.om[1]N)
  nd=${2}/*(/om[1]N)
  [[ -n ${nd} && -n ${nf} ]] && command cp ${nf} ${nd}
}
[snap]

That should work better.

Regards, Frank

-- 
In protocol design, perfection has been reached not when there is
nothing left to add, but when there is nothing left to take away.
                                                  -- RFC 1925



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