python 2.7.12 on Linux behaving differently than on Windows

Michael Torrie torriem at gmail.com
Mon Dec 5 22:57:59 EST 2016


On 12/05/2016 07:25 PM, Dennis Lee Bieber wrote:
> On Mon, 5 Dec 2016 20:55:41 +0000, BartC <bc at freeuk.com> declaimed
> the following:
> 
>> This was a response to someone saying the wildcard param needs to
>> be at the end. There need be no such restriction if handled
>> properly (ie. no auto-expansion).
>> 
> That only applies if there is no prefix indicating a command option 
> from a file name.
> 
>> but one of the files in the list is called "-lm", or some other
>> option
> 
> -lm is not a valid file name on the OS's that use - as an option 
> prefix.

"-" is perfectly valid in a filename on Linux. Getting apps to recognize
it as a filename and not an argument is another story. Convention is to
allow an argument "--" that tells the arg parser that everything
following that is not an argument but a parameter which may or may not
be a file--BartC seems stuck on this point, but parameters could be
anything from urls to string messages to numbers. They don't have to be
files and they in fact could begin with "/" if the program allowed it.

I argue that having convention used by programs and conventions sued by
shells instead of some kind of arbitrary OS-enforced scheme is
inherently more flexible and has its own consistency (everything is
explicit from any program's point of view).

>> Without expansion, input is easy to parse: filespec, followed by 
>> optional options. But with expansion, now you have to decide if a 
>> particular argument is an option, or a filename.
>> 
> And you do that using a delimiter character that is not valid in 
> filenames. On Windows, file names can not have a /, and that is the 
> character used by the command line interpreter to indicate an option 
> follows. On UNIX, - is used as the delimiter of an option.

What is valid in a filename is not relevant here.  No one says
command-line parameters are file names if they aren't an option or
argument.  What a parameter means is up to the application (convention).
 Windows disallows / in a filename.  Linux happens to also.  But Linux
does allow '-' in a filename.  Any character can be used in a parameter
to a program except \0, from the program's point of view.

Back to shell expansion, if I had a file named "-atest.txt" and I passed
an argument to a command like this:

command -a*

The shell would in fact expand that to "-atest.txt" much to BartC's
consternation.



More information about the Python-list mailing list