But there seems to be a problem with by quoting and escaping because if I execute the eval directly like this:
eval "echo \$${VAR_NAME} | sed -n \"/$VAR_REGEXP/p\""
the expected result is printed.
Anyone out there have an idea of how I can capture the result in the VAR_MATCH variable? I ask because I actually need to work with the matched value later on in the script and not simply send it to stdout.
We need more backslash characters to properly escape the eval statement when run from within a shell script.
Also I had to export $USER before invoking the script.
VAR_MATCH=`eval "echo \\$\${VAR_NAME} | sed -n \"/${VAR_REGEXP}/p\""`