7

I have an nginx conf file that due to using environment variables, I have a shell script echo, this file I refer to as nginx.conf.template, then I place the echoed result into the actual nginx.conf, see shell script bellow:

#!/bin/sh
function subst() { eval echo -E "$2"; }
mapfile -c 1 -C subst < nginx.conf.template > nginx.conf

The only issue I have with this is that it removes all whitespace for indentation, I imagine this would cause an issue, but the docker container that I am running this nginx server in seems fine. Does it matter that I have no indentations? If it does matter, can echo preserve said whitespace?

1
  • I ended up just using confd, much better than this hack, but chicks did answer the question at hand I guess Commented Aug 25, 2015 at 19:17

1 Answer 1

5

It isn't removing all of your whitespace. It is reducing each chunk of whitespace to a single space. For most of your nginx.conf this won't hurt anything. If you have quoted strings with multiple spaces those will get changed too by the command above. You can check for that easily by greping for quotes in the template.

Rather than tweaking echo to preserve whitespace it might be easier to build your template as a heredoc in the script.

Getting rid of the extra whitespace could be useful to reduce memory footprints in an embedded environment, but unless you are severely resource constrained maintaining the formatting from template to actual configuration will make debugging much more pleasant.

2
  • Sorry I should clarify, and will, I meant the whitespace in my indentation. Commented Jun 26, 2015 at 18:18
  • the way your shell script is written it does not care whether it is whitespace at the beginning, middle, or end of the line. Commented Jun 26, 2015 at 18:22

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.