Arguments are incorrectly double-quoted when nesting remote commands
See original GitHub issueConsider the following example:
In [2]: from plumbum import SshMachine
In [3]: remote = SshMachine('localhost', ssh_opts=['-tt'])
In [4]: ls = remote['ls']
In [5]: sudo = remote['sudo']
In [6]: print sudo[ls['directory_without_spaces_in_name']]
/usr/bin/sudo /bin/ls directory_without_spaces_in_name
In [7]: print sudo[ls['directory with spaces in name']]
/usr/bin/sudo /bin/ls "'directory with spaces in name'"
In [8]: print ls['directory with spaces in name']
/bin/ls 'directory with spaces in name'
What’s happening here is that the single argument to ls, which contains spaces, gets quoted twice when nested, causing the final argument received by ls to contain an extra set of single quotes (causing the command to return incorrect results).
Note that this type of nesting works as expected with local commands:
In [9]: from plumbum import local
In [10]: ls = local['ls']
In [11]: sudo = local['sudo']
In [12]: print sudo[ls['directory_without_spaces_in_name']]
/usr/bin/sudo /bin/ls directory_without_spaces_in_name
In [13]: print sudo[ls['directory with spaces in name']]
/usr/bin/sudo /bin/ls 'directory with spaces in name'
However, it doesn’t work locally without nesting:
In [14]: print ls['directory with spaces in name']
/bin/ls directory with spaces in name
Am I doing anything wrong? Is there any way to control this behavior?
Issue Analytics
- State:
- Created 8 years ago
- Comments:13
Top Results From Across the Web
Parameters with double quotes are not properly passed to ...
I'm writing generic powershell script to perform deployments on remote machines. I have hit one problem I can not ...
Read more >Nested quotes hell - TechNet - Microsoft
Hi,. I have a powershell script that needs parameters passed to it. We are trying to run through powercenter.
Read more >Nested quotes in subshells - bash - Unix StackExchange
My man bash says "If the substitution appears within double quotes, word splitting and pathname expansion are not performed on the results." (in ......
Read more >5.1. Quoting Variables
[2] An argument enclosed in double quotes presents itself as a single word, ... five words" COMMAND This is $variable1 # Executes COMMAND...
Read more >How to have simple and double quotes in a scripted SSH ...
Using quotes in command arguments is always tricky, as the shell will strip off ... Why has the SSH remote command parsing gone...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Looking at issue #124 and poking at the code, this is my understanding of the problem:
We need explicit control over argument quoting. One way would be to pass some arguments as a new type
RawStringor whatever rather than a native python string to tell plumbum we don’t want any automatic escaping for that arg. That would remove a lot of the elegance of plumbum so that is probably not the way to go. Another option, which I’d personally vote for is to make the programmer responsible for automatically shell escaping strings. Existing packages such aspipesandshlex(py3 only) provide aquotefunction fit for this purpose (at least for non-Windows platforms).Note, one can disable automatic shell-escaping for local commands indirectly thru this ugly hack:
I am running into this issue as well with REMOTE commands. I want to send a
patternargument intounzipand avoid escaping it.Would it be possible to have a
Raw()class that you can enclose arguments in, so escaping is ignored for these arguments. Is this an acceptable solution? @henryiii - I’m happy to submit a patch if no one else has time to get to it - just don’t want to do wasted work as I’m not a regular contributor to this project.