Is it possible, in a clean way to get the variable values when I cat a file, instead of the variable names, as written in the file. It’s hard to explain, but here goes a simple example:
$ cat <<EOF
$HOME
EOF
/home/myself
cat returns /home/myself because it is already expanded by the shell.
$ echo \$HOME >/tmp/home
$ cat /tmp/home
$HOME
cat simply reads the file, I want $HOME to be expanded here somehow by cat, because the file will contain variable names (not like HOME=/home/myself)
My question is if this is possible somehow, otherwise I will have to write some dirty code.
EDIT: they are big xml files containing
<checkbox active="$value">
true or false
This would be trivial to attempt in Python, and see if that works for you. You could use the re.sub function to replace all occurrences of some pattern like
"\$\w+"by calling a function which does the transformation (rather than a specific string to replace it with). And for the replacement function you could useos.getenv(), which of course takes a variable name and returns its value.Edit: Here’s a complete Python script that does the above: