On 21/03/18 10:44, sankarram...@gmail.com wrote:
Hi,

I have a requirement.

cmd="cat <file>|grep -c 'if [ -t 1 ]; then mesg n 2>/dev/null; fi'"

I need to escape only the square brackets in above variable since its not 
grepping without escaping the brackets.

You need to escape the square brackets as you normally would for your shell, with backslashes I presume. Then you need to escape the backslashes so they aren't interpreted specially by Python, with more backslashes.

--
Rhodri James *-* Kynesim Ltd
--
https://mail.python.org/mailman/listinfo/python-list

Reply via email to