Pavel Zagalsky
Pavel Zagalsky

Reputation: 1636

Using raw string properly to send commands over SSH in Python

I have a long long command to send over SSH using Paramiko and I need to wrap the string using "r" parameter but the IDE still tells me it's not written fine. The string is something like that:

somecommand get -n somestuff sa/management --template='{{range .secrets}}{{printf "%s\n" .name}}{{end}}'

I tried doing:

command = r'somecommand get -n somestuff sa/management --template='{{range .secrets}}{{printf "%s\n" .name}}{{end}}'

But got an error. This is probably something super easy to do....

Upvotes: 0

Views: 626

Answers (1)

RainbowRevenge
RainbowRevenge

Reputation: 211

First, you are missing a quote at the end of your string. The second problem is that you can't use quotes inside a string like that.

r'some'thing'

won't work while

r'some"thing'

will work. Since you have quotes in quotes inside the string use a triple-quoted string instead:

r"""some"thi'ng"""

So a working version of your string would be:

command = r"""somecommand get -n somestuff sa/management --template='{{range .secrets}}{{printf "%s\n" .name}}{{end}}'"""

Upvotes: 2

Related Questions