DEV Community

ILshat Khamitov
ILshat Khamitov

Posted on

2 1

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

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs