envsubst icon indicating copy to clipboard operation
envsubst copied to clipboard

Can I get the original value if variable empty

Open jLopezbarb opened this issue 1 year ago • 1 comments

Hi, I need to know if there is a variable in my text that is empty after expanding it. I need those variables not to expand and use the original string.

os.Setenv("GREETINGS", "hello")
value := "$GREETINGS $NAME"
result, err := envsubst.String(value)
if err != nil {
	return "", fmt.Errorf("error expanding environment on '%s': %s", value, err.Error())
}
fmt.Println(result) // The output is: "hello "

Is there a way of getting hello $NAME as the output?

jLopezbarb avatar Jun 01 '23 11:06 jLopezbarb

This would be so helpful.

ashvinsharma avatar Apr 05 '24 11:04 ashvinsharma