FlyingTeller
FlyingTeller

Reputation: 20609

Passing string to python from time

I have a bash script called foo.sh that in this minimal example looks like this:

#!/bin/bash
time $@

and a python script bar.py:

#!/bin/env python
print sys.argv

I want to do something like

bash foo.sh python bar.py "foo bar"

and want "foo bar" to be apssed as a string to the python skript. However I get either

['bar.py', 'foo', 'bar']

or when I do:

bash foo.sh python bar.py \"foo bar\"

I get:

['bar.py', '"foo', 'bar"']

as output. How do I get "foo bar" to be passed and interpreted as a single string to the python script?

Upvotes: 0

Views: 133

Answers (1)

damisan
damisan

Reputation: 1047

Quote the variable in the bash script

#!/bin/bash
time "$@"

Upvotes: 2

Related Questions