/bash-string-template

Replace %WORD% with $WORD in string

Primary LanguageShellMIT LicenseMIT

A simple string template script in bash.

Usage

Usage: string-template '/path/to/%PRJNAME%/'

string-template takes a string as a parameter and looks for occurrences of '%WORD%', replacing that substring with the value of WORD, if it exists in the environment and prints the results to STDOUT.

Example:

PRJNAME=test123 string-template '/path/to/%PRJNAME%

will echo to STDOUT '/path/to/test123'

Note

If WORD does not exist, string-template will print a warning message to STDOUT and replace %WORD% with !!WORD!!.

If WORD does exist but is empty, string-template will replace %WORD% with an empty string.

Tests for this function expect bats to be installed.

Install bats along with bats-support, bats-file, and bats-assert to run tests in this repository.