Read argument with spaces in python script from a shell script
python, shell
Solution
Use `"$@"` instead:
#!/bin/sh
python "$@"
Output:
$ /tmp/test.sh /tmp/test.py firstParam "file with spaces.txt"
['/tmp/test.py', 'firstParam', 'file with spaces.txt']
with `/tmp/test.py` defined as:
import sys
print sys.argv
Problem
How do I read an argument with spaces when running a python script? UPDATE: Looks like my problem is that I'm calling the python script through a shell script: This works: ``` > python script.py firstParam file\ with\ spaces.txt # or > python script.py firstParam "file with spaces.txt" # script.py import sys print sys.argv ``` But, not when I run it through a script: myscript.sh: ``` #!/bin/sh python $@ ``` Prints: ['firstParam', 'file', 'with', 'spaces.txt'] But what I want is: ['firstParam', 'file with spaces.txt']