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

Re: noglob does not call alias?



Hi!

This looked like a mix of cases and
I try to sort some out:

On Thu, 13 Mar 2014, ZyX wrote:

> > $ alias rm='nocorrect rm -i'
...
> > rm: remove regular empty file `1'? n

The question is asked because of alias

> > $ noglob rm 1

aliases are expanded from the beginning of the LINE,
not from the command itself, so anything in front
of 'rm' seems to suppress the alias, like e.g.
FOO=bar rm 1
also does.

> > $ ls
> > 2

So here's no question.

> > I think this is not what (new zsh) user expects.
> > 
> > How do I prevent this?

To prevent 'this', you need to make the
Option '-i' permanent for all 'rm' calls,
which is easier in functions, see at end.

> > Also 'noglob' does not respect RM_STAR_SILENT=off.
> > 
> > $ unsetopt RM_STAR_SILENT
> > $ rm *
> > 
> > zsh: sure you want to delete all the files in ... [yn]? n

Well, it DID ask!

> > rm: missing operand
> > Try `rm --help' for more information.

BUT you still had your alias defined, so you really called

noglob rm -i *

> > First I think when I said 'n'(no), it should not call
> > 'rm' at all instead of calling it without any filename.

THIS is an interesting question!

Why did 'rm *', resulting in 'noglob rm -i *' still execute ???

I assume, the handling of 'denied' case of 'rm *' ends with
a still existing parameter to 'rm', and thus runs the command
instead of ignoring it completely?

> > But, anyway, continuing with my e-mail:
> > 
> > 
> > $ noglob rm *
> > rm: cannot remove `*': No such file or directory

This is, as it should be, and must not reply
differently, lest being incompatible to the
reaction of the other shell variants.



So I think, the only possibly strange case
is the 'dangling -i without filename' created
by the alias.

Such 'strange' effects made me switch completely
from using 'aliases' to 'functions' instead!

For example defining this:

function rm {
         nocorrect command rm -i "$@"
}

might be the 'secured rm' which you tried
to create by aliases and which reacts as
assumed on 'rm *', because the options
are 'inside the function only' and do
not interfere with your typed command.

Stucki

-- 
Christoph von Stuckrad      * * |nickname |Mail <stucki@xxxxxxxxxxxxxxx> \
Freie Universitaet Berlin   |/_*|'stucki' |Tel(Mo.,Mi.):+49 30 838-75 459|
Mathematik & Informatik EDV |\ *|if online|  (Di,Do,Fr):+49 30 77 39 6600|
Takustr. 9 / 14195 Berlin   * * |on IRCnet|Fax(home):   +49 30 77 39 6601/



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