Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

is there an escape character for envsubst?

Is there a way to prevent envsubst from substituting a $VARIABLE? For example, I would expect something like:

export THIS=THAT echo "dont substitute \\\$THIS" | envsubst 

and have it return

dont substitute $THIS 

but instead I get

dont substitute \THAT 

is there any escape character for doing this?

like image 278
quinn Avatar asked Jul 25 '14 20:07

quinn


2 Answers

If you give envsubst a list of variables, it only substitutes those variables, ignoring other substitutions. I'm not exactly sure how it works, but something like the following seems to do what you want:

$ export THIS=THAT FOO=BAR $ echo 'dont substitute $THIS but do substitute $FOO' | envsubst '$FOO' dont substitute $THIS but do substitute BAR 

Note that $THIS is left alone, but $FOO is replaced by BAR.

like image 183
chepner Avatar answered Sep 20 '22 16:09

chepner


export DOLLAR='$'  export THIS=THAT echo '${DOLLAR}THIS' | envsubst 

Or more clear:

export THIS=THAT echo '${DOLLAR}THIS' | DOLLAR='$' envsubst 
like image 38
iokanuon Avatar answered Sep 17 '22 16:09

iokanuon