* Re: noglob does not call alias?
2014-03-13 12:38 ` Christoph (Stucki) von Stuckrad
@ 2014-03-13 13:36 ` ZyX
2014-03-13 14:36 ` Bart Schaefer
2014-03-13 14:48 ` Amm
2 siblings, 0 replies; 8+ messages in thread
From: ZyX @ 2014-03-13 13:36 UTC (permalink / raw)
To: Christoph (Stucki) von Stuckrad; +Cc: zsh-users
13.03.14, 16:50, "Christoph (Stucki) von Stuckrad" <stucki@math.fu-berlin.de>":
>
> 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 "$@"
Corrections happen before function execution. Same for glob expansion. Putting nocorrect modifier here is a no-op, they have to be used from an alias. But putting -i in a function is correct and is the solution to the problem.
>
> }
>
> 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@mi.fu-berlin.de> \
> 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/
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: noglob does not call alias?
2014-03-13 12:38 ` Christoph (Stucki) von Stuckrad
2014-03-13 13:36 ` ZyX
@ 2014-03-13 14:36 ` Bart Schaefer
2014-03-13 15:17 ` Amm
2014-03-13 14:48 ` Amm
2 siblings, 1 reply; 8+ messages in thread
From: Bart Schaefer @ 2014-03-13 14:36 UTC (permalink / raw)
To: zsh-users
On Mar 13, 1:38pm, Christoph (Stucki) von Stuckrad wrote:
}
} 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.
Umm, no. What gave you that idea?
torch% alias rm='echo not removing'
torch% FOO=bar rm 1
not removing 1
However, aliases defined without -g are only expanded in the command
position (occupied by "noglob" in the original example) OR when the
word in command position is itself an alias ending in a space.
So the original complaint can be resolved by
torch% alias noglob='noglob '
torch% noglob rm ?
not removing ?
} 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?
That's correct. The handling for "rm *" actually walks through the
argument list and asks once for every "*" or word ending in "/*" and
if the answer is no, deletes it from the argument list and moves on
to the next one. So "rm * * *" will prompt you three times.
If arguments remain after that, the rm is executed.
--
Barton E. Schaefer
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: noglob does not call alias?
2014-03-13 14:36 ` Bart Schaefer
@ 2014-03-13 15:17 ` Amm
2014-03-13 17:02 ` Bart Schaefer
0 siblings, 1 reply; 8+ messages in thread
From: Amm @ 2014-03-13 15:17 UTC (permalink / raw)
To: zsh-users
On 03/13/2014 08:06 PM, Bart Schaefer wrote:
> However, aliases defined without -g are only expanded in the command
> position (occupied by "noglob" in the original example) OR when the
> word in command position is itself an alias ending in a space.
> So the original complaint can be resolved by
>
> torch% alias noglob='noglob '
> torch% noglob rm ?
> not removing ?
This works if alias rm='rm -i'
but gives error if I have these:
alias rm='nocorrect rm -i'
alias noglob='noglob '
$ noglob rm 1
zsh: command not found: nocorrect
As I already said in my previous e-mail that, zsh needs to consider
noglob and nocommand as special case and treat the next argument as
alias as well as command. (not just command)
Then we will not need the workarounds like create a rm() function or
create alias noglob='noglob '
>
> } 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?
>
> That's correct. The handling for "rm *" actually walks through the
> argument list and asks once for every "*" or word ending in "/*" and
> if the answer is no, deletes it from the argument list and moves on
> to the next one. So "rm * * *" will prompt you three times.
>
> If arguments remain after that, the rm is executed.
Asking 3 times make no sense!
I think purpose of this 'rm *' special handling is to prevent accidental
file deletion. (due to accidental addition of * in arguments)
So if he typed: rm * 1 2 3
And then zsh warns me and then I said "Oh, no I dont want this! And
answe no".
It obvious I made a mistake, So rm should NOT be executed at all (even
if there are arguments remaining)
Let him first manually delete '*' from command and execute rm again.
Amm
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: noglob does not call alias?
2014-03-13 15:17 ` Amm
@ 2014-03-13 17:02 ` Bart Schaefer
0 siblings, 0 replies; 8+ messages in thread
From: Bart Schaefer @ 2014-03-13 17:02 UTC (permalink / raw)
To: zsh-users
On Mar 13, 8:47pm, Amm wrote:
}
} alias rm='nocorrect rm -i'
} alias noglob='noglob '
}
} $ noglob rm 1
} zsh: command not found: nocorrect
This is documented:
nocorrect
Spelling correction is not done on any of the words. This must
appear before any other precommand modifier, as it is interpreted
immediately, before any parsing is done. It has no effect in
non-interactive shells.
The other precommand modifiers are actually builtin commands rather
than reserved words. There is a long list of reasons it ended up
this way which I'm not going to attempt to repeat here, but that is
why their arguments don't get magic treatment at parse time.
--
Barton E. Schaefer
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: noglob does not call alias?
2014-03-13 12:38 ` Christoph (Stucki) von Stuckrad
2014-03-13 13:36 ` ZyX
2014-03-13 14:36 ` Bart Schaefer
@ 2014-03-13 14:48 ` Amm
2 siblings, 0 replies; 8+ messages in thread
From: Amm @ 2014-03-13 14:48 UTC (permalink / raw)
To: zsh-users
On 03/13/2014 06:08 PM, Christoph (Stucki) von Stuckrad wrote:
>>> $ 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.
This I think is wrong. noglob and nocorrect should be treated
as special case and word following should be checked for
existence of alias. (not just command)
>>> 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.
Hmm, then I think functions should be recommended instead of
alias atleast for risky commands like 'rm;
>>> 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
>>> rm: missing operand
>>> Try `rm --help' for more information.
> Well, it DID ask!
Umm, this was not a question. This was part of example.
I was just showing what happens without noglob.
> BUT you still had your alias defined, so you really called
>
> noglob rm -i *
>
As already pointed above noglob does not call rm with -i
Probably you mean nocorrect instead of noglob.
>>> 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?
This actually was side question unrelated to this thread.
>>> But, anyway, continuing with my e-mail:
Here comes the question.
>>> $ 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.
I know, I already stated that this does not cause any harm.
But what I meant that I would still prefer zsh to trigger
a warning whether I used noglob OR not.
I NEVER do 'rm *'. So if there is rm * on command line that surely
means, its by mistake, so I would prefer to see a warning, even if
there is 'noglob'.
> Such 'strange' effects made me switch completely
> from using 'aliases' to 'functions' instead!
Yep, even I think I should switch to 'functions'!
But I would again propose that 'noglob' and 'nocorrect' should
not treat next word as command, it should also check for alias.
Thanks for your replies
Amm
^ permalink raw reply [flat|nested] 8+ messages in thread