This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Shlex does not parse commands containing single quotes correctly
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.7, Python 2.7
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: Anthony Sottile, timonegk
Priority: normal Keywords:

Created on 2019-10-23 21:00 by timonegk, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Messages (3)
msg355265 - (view) Author: (timonegk) Date: 2019-10-23 21:00
Steps to reproduce:
>>> from shlex import split
>>> line = "export F=$'\\''"
>>> split(line)
ValueError: No closing quotation

However, when printing the line

>>> print(line)
export F=$'\''

and pasting the output in bash, no further quotation marks are required.
The behavior of bash is described in its man page (line 497 for me, Chapter Quoting) and occurs also when bash is called with --posix. Therefore I guess that shlex does not reproduce the posix behavior here.
msg355403 - (view) Author: Anthony Sottile (Anthony Sottile) * Date: 2019-10-26 05:02
Try with `sh`:

(it prompts for continuation, I pressed ^D to end it)

$ export F=$'\''
> 
> 
> 
> 
> sh: 8: Syntax error: Unterminated quoted string


dollar-sign strings are a `bash` extension, I don't think they're supported by *sh*lex (maybe if there was a bashlex module :D)

There's the `posix=False` option to `shlex.split` -- I'm not sure what it does/doesn't enable though (the docs aren't thorough here and the code is a bit non-obvious):

>>> shlex.split(s, posix=False)
['export', "F=$'\\''"]
msg355412 - (view) Author: (timonegk) Date: 2019-10-26 11:18
Okay, thanks a lot. I am closing this since it is not a bug then.
History
Date User Action Args
2022-04-11 14:59:22adminsetgithub: 82751
2019-10-26 11:18:40timonegksetstatus: open -> closed
resolution: not a bug
messages: + msg355412

stage: resolved
2019-10-26 05:02:59Anthony Sottilesetnosy: + Anthony Sottile
messages: + msg355403
2019-10-23 21:00:28timonegkcreate