Closed stuartpb closed 10 years ago
Thanks @stuartpb. Yes, I originally used envsubst but found that it would conflict with nginx variables (that look like bash vars). So I went with the perl solution instead, having ${myvar}
be bash vars and $myvar
untouched for nginx vars.
You should be able to backslash-escape the nginx variables, akin to the way they're written in the heredoc versions of the templates. But yes, the curly-brace-restricted version does make the templates a little cleaner looking (although my personal tastes hew closer to wider compatibility).
I recall trying that, but for some reason it did not work. It think it was that the version of envsubst in ubuntu 13.10 had some bug or was too old and ended up ignoring the backslash. I did not check to see if 14.04 resolved the issue.
Haha, wow, guess I spoke too soon (I hadn't tried using it and it has essentially no documentation, so I just assumed like an ass). Just tested it and can confirm I encountered the same issue. (Checking the source confirms this is the expected behavior.)
Anyway, if you'd still like to use $VAR-style substitutions and backslash-escapes, here's an extended version of the Perl one-liner I wrote yesterday to handle that:
perl -pie 's;(\\*)(\$([a-zA-Z_][a-zA-Z_0-9]*)|\$\{([a-zA-Z_][a-zA-Z_0-9]*)\})?;substr($1,0,int(length($1)/2)).($2&&length($1)%2?$2:$ENV{$3||$4});eg'
No worries, thanks for the updated one-liner. I'll test envsubst again sometime and if that works on 14.04, I'll use your perl one-liner as a fallback for 13.10.
I doubt envsubst will be getting backslash escapes any time soon, as its source code gives no indication that it would be under consideration.
Ah, I see. Thank you for taking the time to check envsubst's source.
Withdrawn, templates would need to be changed.