jirutka / esh

Simple templating engine based on shell.
MIT License
214 stars 16 forks source link

The same process that declared a variable will also report an error! #7

Closed robertzhangwenjie closed 4 years ago

robertzhangwenjie commented 4 years ago

image

nginx.tpl.esh

access_log <%= ${HOME}/nginx_access.log %> main;
    error_log <%= ${HOME}/error.lg %>;

    root <%= ${HOME}/APP_NAME %>; 

    <% if  [ -z "$location" ] || [ "${location}" == "/" ] && [ -n "$backend_url" ];then %>
    location / {
      proxy_pass <%= $backend_url %>;
      proxy_set_header Host $host;
    }
    <% fi %>

The same process that declared a variable will also report an error!

jirutka commented 4 years ago

You didn’t export these variables, so they cannot get into esh process, obviously. That’s how the shell works.

You can either pass the variables as arguments to esh (as explained in --help):

esh ./template/nginx.tpl.esh backend_url=1 location=2

or use shell’s feature to pass environment variables for a command:

backend_url=1 location=2 esh ./template/nginx.tpl.esh

or export variables before executing esh:

export backend_url=1
export location=2
esh ./template/nginx.tpl.esh