RH software collections - how to pass arguments ?

Latest response

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.

Hi Bohuslav,

the first way still doesn't work ("Unable to open /etc/scl/prefixes/python simple.py 1 ...") but the second is working correctly.
Thanks for the tip :-)

Hi Przemyslaw,
yes, you're right, my bad. The first option doesn't work when two or more arguments are used (only works with one argument).
Glad I could help.

Hi Bohuslav, This give me back:

scl enable python27 "python simple.py ${@}"

Unable to open /etc/scl/conf/python27!

Any idea why? and strange too: scl --list don't give back anything

What is the output of the following command ?

rpm -qa|grep ^rh-
Close

Welcome! Check out the Getting Started with Red Hat page for quick tours and guides for common tasks.