I need to put some environment variables values to file.
cat file
# $VAR
echo $VAR
# text
When I do envsubst '$VAR $VAR' < file > file
file becomes empty. To resolve this issue I use envsubst '$VAR $VAR' < file | tee file 2>&1 >/dev/null
. But sometimes it doesn't work, I mean file becomes empty. The first question is why sometimes file becomes empty and the second is what is the TRUE Unix way to put env vars to file in Linux and *BSD and MacOS ?