Question

I'm trying to run a python script with several parameters, the tab warnings,optimize and verbose parameters, -t, -O and -v respectively.
#!/usr/bin/python -t -O -v
This is the error that I get when I try to run it this way, ./script.py in the terminal.

Unknown option: - usage: /usr/bin/python [option] ... [-c cmd | -m mod | file | -] [arg] ... Try python -h' for more information.

The script runs well when I have a maximum of one parameter in the shebang. Is it wrong to pass more than one parameter in a python shebang?
Running the script as python -O -t -v script.py at the terminal works.

I'm guessing this is a python issue because I have a perl script that has the following shebang #!/usr/bin/perl -w -t and it runs okay.

The only workaround I came up with was creating a python_runner.sh script to invoked the python interpreter with the three parameters:

#!/bin/sh
python -O -t -v $1
Was it helpful?

Solution

Let's say the file is called test.py and starts with a shebang of:

#!/usr/bin/python -t -O -v

Then calling ./test.py would be the equivalent of the command

/usr/bin/python '-t -O -V' ./test.py

Everything after the first space is treated as one single argument, that's why you can only supply one argument in a shebang. Luckily you can chain shortopts to -tOv.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top