'How to replace a special character in a command to make it useful in the shell

import os
string = "mkdir P&C_directory && pwd'
os.system(string)

shell result is :

string = "mkdir P&d_directory"
In [11]: os.system(string)
sh: 1: d_directory: not found

How to replace any special character in string to "\special_character"



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source