Reply to message «Re: Help with substitute command», 
sent 14:39:35 20 January 2011, Thursday
by Christian Brabandt:

> "Why do I need to script something using
> a loop, if Windows can do it much more easily"?
If you use zsh, these two lines are enough:

    autoload zmv
    alias rename='zmv -W'

Then `rename \*.a \*.b' will work. With this code:

    function zshaddhistory()
    {
        if ! [[ -z "${_HISTLINE}" ]] ; then
            print -sr -- "${_HISTLINE}"
            unset _HISTLINE
        else
            print -sr -- "${1%%$'\n'}"
        fi
        fc -p
    }
    function _accept-line()
    {
        if [[ ${${(z)BUFFER}[1]} == rename ]] ; then
            _HISTLINE=$BUFFER
            BUFFER="rename "${(j. .)${(qqq)${${(z)BUFFER}[2,-1]}}}
        fi
        zle .accept-line
    }
    zle -N accept-line _accept-line

you won't even need to escape anything, so `rename *.a *.b' will work. I don't 
think that this is possible in bash.

Original message:
> On Thu, January 20, 2011 8:08 am, Ben Schmidt wrote:
> > Yeah, it does. Every command does its argument separation itself, too.
> > The Windows APIs only supply the commandline as a string (though the C
> > library of whatever compiler you're using will have some standard way of
> > doing this--mind you, it isn't consistent between libraries, and
> > therefore not consistent between apps, which is a pain). Unless
> > something changed in the last few years, which I don't think it has.
> > 
> > I just never knew the rename command would actually work like that.
> > Fascinating.
> 
> That was actually one of the few things that really annoyed me,
> when switching to Linux.
> 
> "Why do I need to script something using
> a loop, if Windows can do it much more easily"?
> 
> regards,
> Christian

Attachment: signature.asc
Description: This is a digitally signed message part.

Reply via email to