python 2.7.12 on Linux behaving differently than on Windows

Paul Moore p.f.moore at gmail.com
Tue Dec 6 05:51:48 EST 2016


On Monday, 5 December 2016 18:21:57 UTC, Chris Angelico  wrote:
> On Tue, Dec 6, 2016 at 5:02 AM, BartC <bc at freeuk.com> wrote:
> >
> > how do you tell whether the last file in an argument list is the optional
> > 'file', or the last file of the expansion of 'filespec'?
> 
> Why should you care? I have used shell globbing to pass precisely two
> parameters to a program. More often, I use this syntax, which Windows
> simply doesn't support:

You might care. I occasionally teach Unix to beginners, and a common gotcha is the fact that

    cp a/* .

copies everything from a to the current directory. But if you miss typing the ".", the behaviour is *very* different. And the cp command has no way to know or warn you that you might have mistyped.

The find command is another, more "advanced" example.

    find . -name foo*

works as "expected" as long as there's no file that matches the glob in the current directory (because in that case the shell passes the pattern through unchanged). But users who get used to this behaviour get a nasty surprise when they hit a case where it doesn't apply and they *need* to quote.

It's a trade-off. Unix makes shells do globbing, so programs don't have to, but as a consequence they have no means of seeing whether globbing occurred, or switching it off for particular argument positions. Windows chooses to make the trade-off a different way.

Paul



More information about the Python-list mailing list