jmcantrell/bashful

Need few examples usage of flatten_file

first-developer opened this issue · 1 comments

Hi thanks for this helpful libraries,
Please, can't figure out the usage of the helper functions :
https://github.com/jmcantrell/bashful/blob/master/bin/bashful-utils#L605-L639
Do you have more examples (input/output)?
Best regards

Wow. Sorry to leave this hanging for so long.

Given a file like:

Hello, {{PLANET}}!

And an environment variable like:

PLANET=earth

Running flatten_file hello.txt will change hello.txt to:

Hello, earth!

Note that the function will replace any placeholders like {{...}} with the corresponding environment variable value. Since your environment is usually filled with other variables that you might not want in the file, you can be more explicit by changing the above command to flatten_file hello.txt PLANET. I hope it's obvious that you can have more than one placeholder in a file, and if so, be sure to add it to the command arguments.

You can also change the placeholder delimiters by doing something like this before calling the function:

FLATTEN_L="<placeholder>"
FLATTEN_R="</placeholder>"