Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 23218

escaping backtick in shell through python

$
0
0

I have a python script (a.py) that calls a shell script(b.sh). b.sh is responsible for updating a conf file through sed.Here is a sample call.

b.sh -s hello

will save hello in the conf file via an sed command and hello is passed as a parameter to shellscript using python.It is implemented in a way that a service calls the a.py file using the commands module(py2). Which in turn calls the shell script b.sh.

Now I want to save some input that has backticks and looks like belowstrpart1strpart2I cannot escape this because the call is made by python and as soon as backtick hits shell it happens like thisshell not escaping the string

Q1) Can anything be done during call on shell to escape backticks without breaking the string.Now to avoid breaking, I wrote a py2 replace method.

str.replace method

The problem is that when I have to supply an input like below, escaping the backtick.str`example

It is saved as it is.

escaped backtick

However, if I supply input like

sample unbroken string

it is saved as

escaped string

I would like to save it as it is

sample unbroken string

without causing a split on console.

What do I change in python so that the backslashes don't get saved, I have also tried replacing backslashes with (') still the same result. With python, the escape character is also getting saved.


Viewing all articles
Browse latest Browse all 23218

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>