You should try using -- instead of surrounding your command with quotes.

scl enable python27 -- ls /tmp

I was able to make a python script that uses the rh-python35 collection with this shebang:

#!/usr/bin/scl enable rh-python35 -- python

import sys
print(sys.version)
Answer from JM0 on Stack Overflow
Top answer
1 of 3
3

You should try using -- instead of surrounding your command with quotes.

scl enable python27 -- ls /tmp

I was able to make a python script that uses the rh-python35 collection with this shebang:

#!/usr/bin/scl enable rh-python35 -- python

import sys
print(sys.version)
2 of 3
1

The parsing of arguments in the she-bang command is not really defined. From man execve:

The semantics of the optional-arg argument of an interpreter script vary across implementations. On Linux, the entire string following the interpreter name is passed as a single argument to the interpreter, and this string can include white space. However, behavior differs on some other systems. Some systems use the first white space to terminate optional-arg. On some systems, an interpreter script can have multiple arguments, and white spaces in optional-arg are used to delimit the arguments.

No matter what, argument splitting based on quote sis not supported. So when you write:

#!/usr/bin/scl enable python27 "ls /tmp"

It's very possible that what gets invoked is (using bash notation):

'/usr/bin/scl' 'enable' 'python27' '"ls' '/tmp"'

This is probably why it tries to open the "ls file at /etc/scl/prefixes/"ls

But it is just as likely that the shebang evaluates to:

'/usr/bin/scl' 'enable python27 "ls /tmp"'

And that would fail since it wont be able to find a command named enable python27 "ls /tmp" for scl to execute.

There's a few workarounds you can use.

You can call your script via scl:

$ cat myscript
#!/bin/bash
echo hello

$ scl enable python27 ./myscript
hello

You can also use the heredoc notation, but it might lead to subtle issues. I personally avoid this:

$ cat ./myscript
#!/bin/bash
scl enable python27 -- <<EOF
echo hi
echo \$X_SCLS
EOF

$ bash -x myscript 
+ scl enable python27 --
hi
python27

You can see one of the gotcha's already: I had to write \$X_SCLS to access the environment variable instead of just $X_SCL.

Edit: Another option is two have two scripts. One that has the actual code, and the second that simply does scl enable python27 $FIRST_SCRIPT. Then you wont have to remember to enter scl ... manually.

🌐
Gitbook
uaf-rcs.gitbook.io › uaf-rcs-hpc-docs › third-party-software › using-software-collections-scl
Using Software Collections (SCL) | UAF-RCS HPC Documentation
March 28, 2020 - Alternately, individual commands, or scripts, can be executed using the scl command to load desired SCLs just for the duration of that command. For example, put the following in a job script to execute a python script using python 3.6.X instead of the system default version. Copy · /usr/bin/scl enable rh-python36 ./test.py ·
Discussions

linux - Can not limit commands user can run as root in devtoolset-3 enabled shell - Unix & Linux Stack Exchange
We are using devtoolset-3 on RHEL6.6. Users run scl enable devtoolset-3 bash in order to access an environment with all the devtoolset-3 tools. I would like to allow users to run a subset of commands as root. The normal way to do this is to use sudo with a sudoers file containing a command alias with a list of commands you want the user to be able to execute as root. I have tried various combinations but I can't come up with the right recipe. ... If I list /usr/bin... More on unix.stackexchange.com
🌐 unix.stackexchange.com
October 5, 2016
linux - sudo -i returns an error - Unix & Linux Stack Exchange
When I try to switch to root using ... /var/tmp/sclDvf3Vx: line 8: -i: command not found... However, su - works which I will continue to use. I'm by no means a linux system administrator so the environment is still pretty foggy to me. I guess my questions are: ... I'm using CentOS version: CentOS release 6.6 (Final) Here's the output from some commands I was asked to run, in the comments below. type sudo : sudo is /opt/centos/devtoolset-1.1/root/usr/bin/s... More on unix.stackexchange.com
🌐 unix.stackexchange.com
linux - How to permanently enable newer version of software installed from SCL repo? - Unix & Linux Stack Exchange
If it's not 4.7, then you probably have to use devtoolset. If you don't want to run it in SCL, you can uninstall the native gcc with sudo yum remove gcc and then add the devtoolset directory to your path, i.e. put export PATH=$PATH:/opt/centos/devtoolset-1.1/root/usr/bin in your .bashrc. More on unix.stackexchange.com
🌐 unix.stackexchange.com
May 8, 2020
Solved: Bamboo how to set scl enable with docker environme...
Hello :) I am having a hard time to change GCC version on centos image. I use Docker image to build on a centos environment. I made my base image and I tried to use the image. I already set the "scl" command for my base image. I also gave these two commands inside of my Dockerfile. SHELL [... More on community.atlassian.com
🌐 community.atlassian.com
October 10, 2019
🌐
Madboa
madboa.com › blog › 2016 › 08 › 29 › scl-intro
Red Hat/CentOS Software Collections (SCL) - madboa.com
August 29, 2016 - Since SCL packages are off the beaten path, people wanting to use them need to upgrade a variety of environment variables: PATH, LD_LIBRARY_PATH, MANPATH, etc. There are two main ways to do this. There’s a command-line tool, /usr/bin/scl, that eases access to these packages.
🌐
Stack Exchange
unix.stackexchange.com › questions › 311491 › can-not-limit-commands-user-can-run-as-root-in-devtoolset-3-enabled-shell
linux - Can not limit commands user can run as root in devtoolset-3 enabled shell - Unix & Linux Stack Exchange
October 5, 2016 - I have tried various combinations but I can't come up with the right recipe. ... If I list /usr/bin/scl as an allowed command then the user is allowed to execute any command as root in an scl enabled environment.
🌐
Softwarecollections
softwarecollections.org › en › docs › guide
Packaging Guide — Software Collections
The wrapper installed in /usr/bin/ sets up the correct environment and executes the target binary located withing the /opt/provider/%{scl} file system hierarchy.
Find elsewhere
🌐
Utk
help.eecs.utk.edu › knowledge-base › linux-topics › using-redhat-software-collections
Using Red Hat Software Collections [EECS IT Help]
By running scl enable <collection name> <shell> you can start a new shell where the software contained in the collection is now the default. RHEL 7 ships with a very stable but old version of Python, 2.7.5. You can check the currently default Python version with the python –version command: ... As you can see, Python is executed from the default system binary location of /usr/bin.
🌐
Linux Man Pages
linux.die.net › man › 1 › scl
scl(1) - Linux man page
scl utility allows to execute an application which is not located in the filesystem root hierarchy but is present in an alternative location. This application can still use and benefit from software installed in the root filesystem.
Top answer
1 of 5
93

In your ~/.bashrc or ~/.bash_profile Simply source the "enable" script provided with the devtoolset. For example, with the Devtoolset 2, the command is:

source /opt/rh/devtoolset-2/enable

or

source scl_source enable devtoolset-2

Lot more efficient: no forkbomb, no tricky shell

2 of 5
17

An alternative of source /opt/rh/devtoolset-4/enable is

source scl_source enable devtoolset-4

The above shell script scl_source is more elegant than using a hard coded path (may be different on another machine). However scl_source does less because /opt/rh/devtoolset-4/enable uses scl_source and other stuff.

To use scl_source you may have to upgrade package scl-utils

yum update scl-utils  # old scl-utils versions miss scl_source

Quick copy-paste

echo 'source scl_source enable devtoolset-4' >> ~/.bashrc
    # Do not forget to change the version ↑

Source code for curious people

An example of scl_source source code:
https://gist.github.com/bkabrda/6435016

The scl_source installed on my Red Hat 7.1

#!/bin/bash

_scl_source_help="Usage: source scl_source <action> [<collection> ...]

Don't use this script outside of SCL scriptlets!

Options:
    -h, --help    display this help and exit"

if [ $# -eq 0 -o $1 = "-h" -o $1 = "--help" ]; then
    echo "$_scl_source_help"
    return 0
fi


if [ -z "$_recursion" ]; then
    _recursion="false"
fi
if [ -z "$_scl_scriptlet_name" ]; then
    # The only allowed action in the case of recursion is the same
    # as was the original
    _scl_scriptlet_name=$1
fi
shift 1

if [ -z "$_scl_dir" ]; then
    # No need to re-define the directory twice
    _scl_dir=/etc/scl/conf
    if [ ! -e $_scl_dir ]; then
        _scl_dir=/etc/scl/prefixes
    fi
fi

for arg in "$@"; do
    _scl_prefix_file=$_scl_dir/$arg
    _scl_prefix=`cat $_scl_prefix_file 2> /dev/null`
    if [ $? -ne 0 ]; then
        echo "Can't read $_scl_prefix_file, $arg is probably not installed."
        return 1
    fi

    # First check if the collection is already in the list
    # of collections to be enabled
    for scl in ${_scls[@]}; do
        if [ $arg == $scl ]; then
            continue 2
        fi
    done

    # Now check if the collection isn't already enabled
    /usr/bin/scl_enabled $arg > /dev/null 2> /dev/null
    if [ $? -ne 0 ]; then
        _scls+=($arg)
        _scl_prefixes+=($_scl_prefix)
    fi;
done

if [ $_recursion == "false" ]; then
    _i=0
    _recursion="true"
    while [ $_i -lt ${#_scls[@]} ]; do
        _scl_scriptlet_path="${_scl_prefixes[$_i]}/${_scls[$_i]}/${_scl_scriptlet_name}"
        source "$_scl_scriptlet_path"
        if [ $? -ne 0 ]; then
            echo "Can't source $_scl_scriptlet_name, skipping."
        else
            export X_SCLS="${_scls[$_i]} $X_SCLS"
        fi;
        _i=$(($_i+1))
    done
    _scls=()
    _scl_prefixes=()
    _scl_scriptlet_name=""
    _recursion="false"
fi
🌐
Red Hat
access.redhat.com › solutions › 1252913
How to use Red Hat Software Collections in scripts and cron jobs - Red Hat Customer Portal
Adjust the script header to use #!/usr/bin/env python as the scripts interpreter definition and setup cron, enabling Red Hat Software Collections 30 * * * * scl enable python27 <path to script>/python_script.py
🌐
Oracle
docs.oracle.com › cd › F61410_01 › scl-user › OL-SCL-USER.pdf pdf
Oracle Linux Software Collection Library for Oracle Linux 7 E59096-28
#!/bin/bash · scl enable php55 -- php $@ Starting with version 3.0, the scl utility can be called directly from the shebang (#!) line of a · script, with the enable action provided. This feature change enables you to call an interpreter · from within a collection directly from your scripts, for example: #!/usr/bin/scl enable rh-python36 -- python ·
🌐
Indico
indico.math.cnrs.fr › event › 208 › contributions › 1031 › attachments › 570 › 623 › software_collections.pdf pdf
Les ”Software Collections” : kesako ? Zouhir Hafidi
scl-utils : /usr/bin/scl et /etc/scl/prefixes · scl-utils-build : pour les packagers · Mathrice 2014, Grenoble · Les ”Software Collections” : kesako ? Exemple 1 : ownCloud 6 + PHP 5.4 sur CentOS 6.5 · Installation du repo : # yum install centos-release-SCL ·
🌐
GitHub
github.com › composer › composer › issues › 7852
Composer fails to run on CentOS 7 with SCL enabled · Issue #7852 · composer/composer
December 22, 2018 - Red Hat ships antique versions of the programs so users have to enable SCL to get into a good state. The situation pretty much sucks. I'd rather be dragged across hot rocks and broken glass than deal with this shit. ... I have no idea what this file is or where it is located. find /usr/share -name composer.json returns about 50 of them.
Author   composer
🌐
Red Hat
developers.redhat.com › blog › 2017 › 10 › 18 › use-software-collections-without-bothering-alternative-path
Use Software Collections without Bothering with Alternative Path | Red Hat Developer
November 1, 2023 - For example, they need to use 'scl enable' call, which changes environment variables like PATH or LD_LIBRARY_PATH, so that binaries under alternative path are found. Users also need to use different names for systemd services. Or, some scripts might use full paths for the binaries, like /usr/bin...
🌐
GitHub
github.com › openshift › puppet-openshift_origin › issues › 303
scl-utils is not properly installing, causing openshift-node-web-proxy to fail to start · Issue #303 · openshift/puppet-openshift_origin
September 27, 2014 - [root@broker ~]# service openshift-node-web-proxy restart Stopping node-web-proxy: [ OK ] Starting node-web-proxy: /opt/rh/nodejs010//enable: line 5: scl_source: No such file or directory
Author   openshift
🌐
Stack Overflow
stackoverflow.com › questions › 43880358 › scl-enable-not-setting-path-with-bash
software collections - 'scl enable' not setting PATH with bash - Stack Overflow
$ scl --list devtoolset-4 python27 rh-java-common rh-perl524 rh-python35 $ which python /usr/bin/python $ python --version Python 2.6.6 $ scl enable python27 bash $ which python /usr/bin/python $ python --version Python 2.6.6 $ cat /opt/rh/python27/enable export PATH=/opt/rh/python27/root/usr/bin${PATH:+:${PATH}} export LD_LIBRARY_PATH=/opt/rh/python27/root/usr/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}} export MANPATH=/opt/rh/python27/root/usr/share/man:${MANPATH} # For systemtap export XDG_DATA_DIRS=/opt/rh/python27/root/usr/share:${XDG_DATA_DIRS:-/usr/local/share:/usr/share} # For pkg-conf