The scl enable ... command creates a new shell; you've probably ended up with several nested layers of shells if you've been testing this. If you exit, you'll probably see the gcc --version output from the base system. See how deeply-nested you are with something like pstree -s $$.

To run gcc --version with scl, just put the command on the scl line:

 scl enable devtoolset-9 'gcc --version'

Reference: The Red Hat Developer Toolset 9 User Guide (pdf).

Answer from Jeff Schaller on Stack Exchange
Discussions

Scl enable devtoolset-7 bash on Rocky 9
I didn’t find scl or devtoolset-7 to install. How should I do? Thank you very much. More on forums.rockylinux.org
🌐 forums.rockylinux.org
16
0
March 9, 2023
bash - Issue running multiple shell scripts inside a shell script - Stack Overflow
So that bash command specified at the end of scl enable devtoolset-9 bash was waiting for input from you, which is why it didn't terminate (and you don't see which gcc running) and so on. You've got the same issue at the end of script_2.sh — what about the other scripts? More on stackoverflow.com
🌐 stackoverflow.com
March 5, 2021
Installing devtoolset-X
$ sudo dnf search toolset Last metadata expiration check: 2:26:13 ago on Mon 15 Nov 2021 05:10:30 AM EST. ============================================= Name & Summary Matched: toolset ==== gcc-toolset-10.x86_64 : Package that installs gcc-toolset-10 gcc-toolset-10-runtime.x86_64 : Package that handles gcc-toolset-10 Software Collection. gcc-toolset-11.x86_64 : Package that installs gcc-toolset-11 gcc-toolset-11-runtime.x86_64 : Package that handles gcc-toolset-11 Software Collection. gcc-toolset-9.x86_64 : Package that installs gcc-toolset-9 gcc-toolset-9-runtime.x86_64 : Package that handles gcc-toolset-9 Software Collection. So do dnf-install gcc-toolset-X, then scl enable devtoolset-X bash More on reddit.com
🌐 r/AlmaLinux
1
7
November 14, 2021
linux - How to use devtoolset in autotools - Stack Overflow
I want to enable devtoolset-9 from autotools i.e. from configure.ac. I need to do this as I am using gcc 4 and gcc 9 both for the compilation. I know the option scl enable devtoolset-9 'make' but w... More on stackoverflow.com
🌐 stackoverflow.com
🌐
GitHub
gist.github.com › superzscy › ea619f881c92b8cdae8faaf782d0f031
Installing-GCC-9-on-CentOS-7.md · GitHub
yum install -y centos-release-scl yum install -y devtoolset-9 scl enable devtoolset-9 bash
🌐
JLab Wiki
wiki.jlab.org › epsciwiki › index.php › Using_devtoolset-9_on_your_RHEL7_desktop › laptop
Using devtoolset-9 on your RHEL7 desktop/laptop - epsciwiki
sudo yum install devtoolset-9 · To use the tools from a given toolset, you need to launch a new shell with those enabled via: scl enable devtoolset-9 tcsh · You will need to do this for every shell you use with the toolset.
🌐
JetBrains
intellij-support.jetbrains.com › hc › en-us › community › posts › 360004312319-enable-scl-devtoolset
enable scl devtoolset – IDEs Support (IntelliJ Platform) | JetBrains
So all you have to do is tell CLion to point towards what devtoolset is providing. When you do scl enable devtoolset, it is simply pointing towards what devtoolset provides.
Find elsewhere
🌐
Posit Support
support.posit.co › hc › en-us › articles › 360006145413-RStudio-Workbench-RStudio-Server-Pro-with-devtoolset-enabled
Posit Workbench with devtoolset enabled – Posit Support
July 25, 2024 - source scl_source enable devtoolset-9 · 3. Allow access to the file with: chmod 755 /etc/rstudio/rsession-profile · 4. This will apply to all new sessions now. You may wish to restart the service to force any existing sessions to reload.
Top answer
1 of 1
1

Copying comments into the semblance of an answer.

Change the sh script_1.sh etc lines to bash -x script_1.sh (or sh -x script_1.sh since the scripts don't seem to use any Bash-specific syntax) and monitor what's going on. Do you see the version information from gcc --version in script_1.sh?

gcc --version is only printed when I comment out scl enable devtoolset-9 bash. I ran scl enable devtoolset-9 bash and it does not output anything to the screen.

That suggests the scl command is not completing. Maybe it is waiting for input from the terminal. Do you see the output from which gcc when you include the scl command? If not, then it is close to certain that scl is trying to read from the terminal. I dunno what it's reading — it isn't a command I'm familiar with.

It is not waiting for any input. After execution, it brings the prompt again when I run it by itself.

If you're not seeing the which gcc and gcc --version output, then it is probable that the scl command is not completing, IMO. What does the bash at the end of the command options do? Does it run a bash process? If so, where is its input coming from? Running with the -x option (sh -x script_1.sh) would show you what is being executed, and whether scl is completing.

scl enable foo bar bash actually runs a bash instance with foo and bar Software Collections enabled. See https://linux.die.net/man/1/scl

OK; and what is that bash instance doing? Is it not waiting for input before it executes anything? It's a little surprising that there isn't a prompt, but not completely astonishing. Have you tried typing exit when scl hangs?

I just tried scl enable devtoolset-9 bash & echo "Enabling devtoolset-9" and it works and ultimately prints out the gcc --version.

Well, that & runs the scl command in background, leaving the echo to run, and then which gcc and gcc --version. Replace the & with a semicolon. Or replace the & with -c 'echo Hi' and a semicolon and see what happens.

Wonderful! Adding -c echo "Hi" made it work!

So that bash command specified at the end of scl enable devtoolset-9 bash was waiting for input from you, which is why it didn't terminate (and you don't see which gcc running) and so on. You've got the same issue at the end of script_2.sh — what about the other scripts? But you now know what's going on and can decide what to do about it. Using -c exit would simply terminate the shell (instead of echoing Hi), for example.

I'd need to study the scl command more, but do you actually need to use it in these scripts?

🌐
GitHub
gist.github.com › nchaigne › ad06bc867f911a3c0d32939f1e930a11
Building GCC 9.2.0 on CentOS 7 · GitHub
yum install centos-release-scl -y yum clean all yum install devtoolset-9-* -y scl enable devtoolset-9 bash
🌐
Stack Overflow
stackoverflow.com › questions › 61713954 › how-to-use-devtoolset-in-autotools
linux - How to use devtoolset in autotools - Stack Overflow
I tried multiple options like setting up SHELL, CC variable as CC='source scl_source enable devtoolset-9; gcc' but none of them worked.
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
🌐
Ucsd
browndye.ucsd.edu › download.html
Download & Installation
yum install centos-release-scl epel-release yum install devtoolset-9 ocaml expat-devel lapack-devel apbs scl enable devtoolset-9 bash
🌐
Red Hat
bugzilla.redhat.com › show_bug.cgi
Full Text Bug Listing
Red Hat Bugzilla – Full Text Bug Listing · This site requires JavaScript to be enabled to function correctly, please enable it · Note: This bug is displayed in read-only format because the product is no longer active in Red Hat Bugzilla · Bug 1946150 · Privacy Contact FAQ Legal