Search code examples
pythonbashescaping

python bash how to escape character '!'?


python/bash how to escape character '!'

I am try to run in Python this

c.run('sqlcmd -U nrv -P PP!asword -Q "select top 3 * from sys.databases"', pty = True)

code in brackets - bash code

it works in terminal in that manner:

sqlcmd -U nrv -P PP\!asword -Q "select top 3 * from sys.databases"

in genereal i try nothing meaningful


Solution

  • has answer! c.sudo(r'''sqlcmd -U nrv -P PP!asword -Q "select top 3 * from sys.databases"''') (in that case I've changed run to sudo because sufficient privileges)

    so, I newbie in Python, and heared about "sсreened" strings - and it simply works.it's even strange that a backslash was not required, because command in brackets - it is a bash, and it requires.