Questions about windows support
H. S. Teoh
hsteoh at quickfur.ath.cx
Mon Feb 27 09:47:16 PST 2012
On Sun, Feb 26, 2012 at 05:10:35PM -0500, Nick Sabalausky wrote:
[...]
> I've just thought of (ie, gotten bit by) another thing that would be
> nice about having the commands do their own globbing:
>
> If the applications glob on their own insted of the shell, then for
> safety they can choose to restrict the number of file args they take
> to whatever makes sense for their own individual purpose.
>
> For example, suppose you want to delete everything inside a given
> subdirectory (but keep the directory itself). So then you (mis)type:
>
> $rm somedir/ * -rf
>
> Note the subtle space before the "*". I just did that by mistake
> earlier today, and the damage set me back a few hours (could have been
> much, much worse, though). I don't think there's much, if anything,
> that can realistically be done to protect against that right now. At
> least without getting really hacky.
If rm did its own globbing, it could warn the user before proceeding
with a mass deletion involving *. (IIRC DOS's 'del' used to do this.)
With the shell doing the expansion, there's no easy way to do this.
> But, if rm was expected to do its own globbing instead of the shell
> doing it, then rm could say: "Ok, it only makes sense for you to give
> me one file/path at a time. Want more? Run me multiple times or use a
> glob pattern (or hell, a regex pattern, or use a special explicit
> 'accept multiple paths' mode, etc)." Then:
>
> $rm somedir/ * -rf
> ERROR: rm only takes one path at a time
> $rm somedir/* -rf # ok
> $rm somedir/ -rf # ok
> $rm * -rf # ok
>
> With the shell doing the expansion, that sort of thing isn't even
> possible.
I guess you could have a flag for when you explicitly want to specify
multiple filenames:
$ rm abc.d def.d
ERROR: rm only takes one path at a time
$ rm -m abc.d def.d # ok
$
> Works with other stuff too:
>
> $cp a b c
> ERROR: You gave me a source path and a destination path, but then you
> gave me *another* path! What the hell you expect *me* to do with it?
[...]
But sometimes you want to copy multiple files to a destination dir. But
I suppose you can always use a glob or specify an option to say "yes I
really want to copy multiple files into a target dir".
T
--
It is impossible to make anything foolproof because fools are so ingenious. -- Sammy
More information about the Digitalmars-d
mailing list