I am calling a python script, parse_input.py from bash
parse_input.py takes a command line argument that has many '\n' characters in it.
Example input:
$ python parse_input.py "1\n2\n"
import sys
import pdb
if __name__ == "__main__":
assert(len(sys.argv) == 2)
data = sys.argv[1]
pdb.set_trace()
print data
I can see on pdb that `data = "1\\n2\\n" whereas I want data="1\n2\n"
I saw similar behavior with just \ (without \n) which gets replaced by \\
How to remove the extra \ ?
I don’t want the script to deal with the extra \ as
the same input can also be received from a file.
bash version: GNU bash, version 4.2.24(1)-release (i686-pc-linux-gnu)
python version : 2.7.3
Bash doesn’t interpret escape characters in regular single and double-quoted strings. To get it to interpret (some) escape characters, you can use
$'...':i.e.