python - How to escape spaces in Bash command line arguments -
does bash support escaping spaces in command line arguments?
i have simple python script using argparse arguments passed bash, when call like:
myscript.py --name="some text spaces"
i result like:
args = ['text', 'with' spaces'] kwargs = {'name': 'some'}
i though bash support spaces "\" trying
myscript.py --name="some\ text\ with\ spaces"
results in same thing.
am misusing bash, or problem have deal on python's side?
coming bash end, cause you're not telling truth bash code. you're hitting looks great deal bashfaq #50.
running
myscript.py --name="some text spaces"
...directly command line works perfectly, resulting in sys.argv
array of ['myscript.py', '--name=some text spaces']
. behavior describe consistent this:
cmd='myscript.py --name="some text spaces"' $cmd
...which result in sys.argv
array of ['myscript.py', '--name="some', 'text', 'with', 'spaces"']
.
don't that, ever. either use array (typically appropriate if need build argument line conditionally):
cmd=( myscript.py --name="some text spaces" ) "${cmd[@]}"
...or function (typically appropriate choice in other cases):
myscript() { myscript.py --name="some text spaces" "$@"; } myscript
Comments
Post a Comment