RH software collections - how to pass arguments ?
Hi all,
I am trying to write python script running on RH 6 using python 2.7 from Software Collections (SCL).
Since I couldn't find any way to use shebang with SCL I am trying to use
a workaround: run bash script which enables python27 SCL and run python script.
The script should recognize all arguments and pass it to python:
#!/bin/bash
/usr/bin/scl enable python27 'python simple.py ${@}'
The simple.py:
import sys
print len(sys.argv)
print sys.argv
sys.exit(0)
But it doesn't work - no arguments are passed to python script.
Can anybody help me ?
How can I do that ?
Responses
In short, the problem is in the single quotes.
When passing 'python simple.py ${@}' to /usr/bin/scl, the command is in fact run in a newly created scl-enabled subshell. Because of the single quotes, the shortcut for all params ${@} doesn't get expanded in the parent shell (the shell in your script), but in the scl-enabled subshell, where it's empty.
You can fix this in few ways:
- Use double quotes, so that the variable gets expanded in current shell:
/usr/bin/scl enable python27 "python simple.py ${@}"
- Keep using the single quotes, but pass the variable to subshell in a different way:
allparams=${@} /usr/bin/scl enable python27 'python simple.py $allparams'
Hope this helps.
Welcome! Check out the Getting Started with Red Hat page for quick tours and guides for common tasks.
