python - Seaming incorrect parsing of a string in shlex - Stack Overflow

admin2025-04-21  1

So I have a program that is passing down commands to a remote host and using shlex library to parse the args that way a incompleted quotation will not be sent down. And I notice this behavior

here is my intended behavior and working behavior on a string like this:

>>> lexer = shlex.shlex('"aaaaaaaaaaaaaaaa')
>>> list(lexer)
ValueError: No closing quotation 

However for

>>> lexer = shlex.shlex('"\\"')
>>> list(lexer)
['"\\"']

Which of course when I run this on the remote host we are getting a waiting since its running this in bash "\". I would expect the above input to also give me a Value Error since the string is not closed.

Is this shlex intended behavor and if so why?

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1745241524a292037.html

最新回复(0)