I can find plenty of answers which uses echo, pipes | and sed for that purpose, but I would like to avoid them. So looking for some direct substitution.
I would like to define env var and reuse it inside the character string passed to application command line argument, i.e. Rscript -e '...'.
Below is what I've tried without success.
Rscript -e 'cat("hello\n")'
#hello
export ASD="HELLO!"
Rscript -e 'cat("$ASD\n")'
#$ASD
Rscript -e 'cat("${ASD}\n")'
#${ASD}
Rscript -e 'cat("$(ASD)\n")'
#$(ASD)
I don't want to use echo and | pipes as my actual -e argument to application is much more complex.
'cat("'"$ASD"'")'be what you are looking for?Rscript, we can't possibly know howcat(...)will be interpreted by it. By usingeval, you may be able to use the$ASDvariable within the script after referring to it by name on the command line. But that's probably not the best way to solve your underlying problem. In your example above (or rici's alternative), what happens if$ASDcontains a quote or a close bracket?