Recursive replace input value with process environment values in console

ILshat Khamitov - Mar 27 '22 - - Dev Community

Often you need to change part of the value of an environment variable to another variable

I made a utility for such a replacement

Links

https://www.npmjs.com/package/rucken - npm package

https://github.com/rucken/rucken - source code

https://github.com/rucken/rucken/blob/develop/libs/rucken/tests/e2e/env-replacer.spec.ts - e2e test

Example of usage

Create env file
example.env

VAR1=var1${VAR2}
VAR2=var2$var3
var3=VAR3$NO_REPLACE
Enter fullscreen mode Exit fullscreen mode

Load file to current environment

export $(cat ./example.env)

We derive the variable VAR1 in the usual way

echo $VAR1

Result

var1${VAR2}
Enter fullscreen mode Exit fullscreen mode

And now we will display the variable through the utility

echo $(npx -y rucken env-replacer $VAR1)

Result

var1var2VAR3$NO_REPLACE
Enter fullscreen mode Exit fullscreen mode
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Terabox Video Player