Search code examples
pythonbashshellsubprocesspopen

How can I run this shell script inside python?


I want to run a bash script from a python program. The script has a command like this:

find . -type d -exec bash -c 'cd "$0" && gunzip -c *.gz | cut -f 3 >> ../mydoc.txt' {} \;

Normally I would run a subprocess call like:

subprocess.call('ls | wc -l', shell=True)

But that's not possible here because of the quoting signs. Any suggestions?

Thanks!


Solution

  • Escape the ' marks with a \.

    i.e. For every: ', replace with: \'