I am activating a scl python environment in a shell script and would like to do some custom installation of virtualenv based on arguments. However, I cannot pass variables from my shell/bash script into the subshell created when I activated the scl environment. How could I access the arguments defined in the shell/bash script?
$ARG=argument
scl enable rh-python36 << SS
echo $ARG
SS
For example when I run the above script, output will be:
line 1: ARG: command not found
I'm not familiar with scl at all, but I can point out some things that're wrong with the shell part of what you're doing:
Use $
with variable to get their values, not when setting them. Therefore, $ARG=argument
should be ARG=argument
. BTW, the error message you gave doesn't actually match this problem; it looks more like what you'd get with spaces around the =
(e.g. ARG = argument
), which isn't allowed because it'll treat ARG
as a command, and "=
" and "argument
" as arguments to pass to it. In general, spaces are important delimiters in the shell, and adding or removing them -- even in unimportant-looking places -- can completely change the meaning of a command.
By default, variables are private to the shell itself. To make the variable available to scl
(and any other commands you run in the shell), you need to export
it. Thus, you actually want:
export ARG=argument
I recommend against using all-caps variable names, since there are a number of all-caps names that have special meanings; using one of those for something else can have weird effects. Lower- and mixed-case variable names are safer.
Inside a regular here-document (the part that << SS
opens), the shell will expand $variable
expressions before sending the document to the program. If you want that $
expression to be sent to the program for it to interpret, you need to either quote the here-doc delimiter (e.g. << "SS"
), or backslash-escape all dollar-signs, backticks, and backslash characters in the document.