[New-bugs-announce] [issue40363] shlex.quote applied to a glob pattern disables glob matching

Jack Orenstein report at bugs.python.org
Wed Apr 22 11:21:31 EDT 2020


New submission from Jack Orenstein <jao at geophile.com>:

I am using shlex.quote to pass filenames to a shell command, e.g. ls. The problem is that glob patterns, when quoted, no longer operate as glob patterns. So, for example, executing this:

    ls 'var/log/syslog*'

results in this output:

    ls: cannot access '/var/log/syslog*': No such file or directory

The documentation for shlex.quote says: "Return a shell-escaped version of the string s. The returned value is a string that can safely be used as one token in a shell command line, for cases where you cannot use a list."

I believe that quoting needs to preserve glob semantics to fulfill the documented goal. For example, it seems to me that quoting as follows would be better:

    ls '/var/log/syslog'*

----------
components: Library (Lib)
messages: 367010
nosy: geophile
priority: normal
severity: normal
status: open
title: shlex.quote applied to a glob pattern disables glob matching
versions: Python 3.7

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue40363>
_______________________________________


More information about the New-bugs-announce mailing list