Call the perl binary, in search and replace per line mode ( the -pi
) by running the perl code ( the -e
) in the single quotes, which iterates over the keys of the special %ENV
hash containing the exported variable names as keys and the exported variable values as the keys' values and for each iteration simple replace a string containing a $<<key>>
with its <<value>>
.
perl -pi -e 'foreach $key(sort keys %ENV){ s/\$$key/$ENV{$key}/g}' file
Caveat: An additional logic handling is required for cases in which two or more vars start with the same string ...