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

Re: alias/anon_function quoting issue



On Thu, Jul 27, 2023 at 1:51 AM Johan Grande <nahoj@xxxxxxxxx> wrote:
>
> Le 14/07/2023 à 16:46, Jim a écrit :
> >
> > alias name='(){ ... }'
>
> Hi, I'm curious, is there a particular advantage to doing this rather
> than declaring a function?

I can think of only a couple.

First, you can define a suffix alias this way:

alias -s tgz='() { tar -tzf - < $1 }'

Second, with an alias you can use simple quoting to switch back to a
command of the same name.  In this example:

vim() { gvim "$@" }
\vim foo

the "vim" function is still executed and you get gvim.  But with this:

alias vim='() { gvim "$@" }'
\vim foo

the alias is not expanded and /bin/vim runs directly.

If there are other reasons they don't occur to me offhand.




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