3

Recursive replace input value with process environment values in console

 2 years ago
source link: https://dev.to/endykaufman/recursive-replace-input-value-with-process-environment-values-in-console-2mcm
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Recursive replace input value with process environment values in console

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


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK