Working with Ruby shell executions by a backquote or %x
syntax I found that when I declare a new variable in bash it is not visible by ruby script, until I make it environment by export
command.
Please explain mechanism why do Shell Variables is not visible by a script?
# Shell and Environment variables.
V123='This is an variable. VAR HERE.'
echo $V123
# Read shell variable via Ruby
ruby -e 'p `echo $V123`' # "$V123\n"
ruby -e 'p %x[echo $V123]' # "$V123\n"
# Check SET for this var
set | grep V123
ruby -e 'p `set | grep V123`' # ""
ruby -e 'p %x[set | grep V123]' # ""
# Put this var itno the Environment
echo "--- Export"
printenv V123
export V123
printenv V123
echo "--- Ruby printenv"
ruby -e 'p `printenv V123`' # This is an variable. VAR HERE.\n"
ruby -e 'p %x[printenv V123]' # This is an variable. VAR HERE.\n"