FG
💻 Software

How do I substitute environment variables when I ouput a file?

Fresh7 days ago
Mar 15, 202619489 views
Confidence Score0%
0%

Problem

I'd like to somehow spit out a file (which has env variable references) and substitute the actual values. This is what I've tried, but as you can see it's not working. Any ideas?

Error Output

-bash-3.00$ cat vars_file 
${MY_VAR}
-bash-3.00$ export MY_VAR=MY_VALUE; cat ./vars_file | xargs echo
${MY_VAR}

Unverified for your environment

Select your OS to check compatibility.

1 Fix

Canonical Fix
Unverified Fix
New Fix – Awaiting Verification

Fix for: How do I substitute environment variables when I ouput a file?

Low Risk

Old thread, but this is a recurrent issue. Here is a solution using bash's : The bash builtin calls user-defined function (see -C/-c options) on each line read from input file . Since the line contains unescaped text, is used tu evaluate it and the …

Awaiting Verification

Be the first to verify this fix

Sign in to verify this fix

Environment