0

Sorry this is a very newbie question, but I just can't seem to get it to work.

in my bash script, I have

python=/path/to/python
script=$1
exec $python $script "$@"

How would I pass an argument, say -O to the python interpreter? I have tried:

exec $python -O $script "$@"

And have tried changing python variable to "/path/to/python -O", as well as passing -O to the script, but every time i do any of these three, I get import errors for modules that succeed when I remove the -O.

So my question is how to tell the python interpreter to run with -O argument from a bash script?

Thanks.

1
  • 1
    While your script does not appear to solve any useful problem (and lacks a shift) the obvious and correct solution is what you have already tried, i.e. python -O scriptname.py "$@". Find out why those modules don't work with -O instead. Posting an error message here, or perhaps better yet posting a new question - and perhaps deleting this one - seems like the road forward. Commented Sep 1, 2013 at 21:24

1 Answer 1

1

You should shift your positional parameters to the left by 1 to exclude your script which is in the first arguments from being included to the arguments for python.

#!/bin/sh
python=/path/to/python
script=$1; shift
exec "$python" -O "$script" "$@"

Then run the script as bash script.sh your_python_script arg1 arg2 ... or sh script.sh your_python_script arg1 arg2 ....

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.