esh (embedded shell) is a templating engine for evaluating shell commands embedded in arbitrary templates. It’s like ERB (Embedded RuBy) for shell, intended to be used for templating configuration files. Unlike ERB it provides support for including one ESH template into another (since version 0.2.0).
The template processing consists of two phases: conversion to a shell script and evaluation of that script.
You can even run just the conversion phase: esh -d
will dump a shell script that you can execute directly by a shell (even on a system without esh
installed).
However, in that case, you will not get error messages source-mapped to point to the locations in the template file.
esh is implemented in ~290 lines (LoC) of shell and awk.
-
POSIX-sh compatible shell (e.g. Busybox ash, dash, ZSH, bash, …)
-
common Unix userland with
awk
andsed
(e.g. from Busybox, GNU, …) -
(Asciidoctor to build a man page)
You can add esh as a submodule into your repository or download it on demand, e.g.:
wget https://raw.githubusercontent.com/jirutka/esh/v0.3.2/esh \
&& echo '9084e3e8e70e4ea81c40cd1cf85559196c0fa2cc esh' | sha1sum -c \
|| exit 1
-
Download and unpack release tarball:
wget https://github.com/jirutka/esh/archive/v0.3.2/esh-0.3.2.tar.gz tar -xzf esh-0.3.2.tar.gz cd esh-0.3.2
-
Run tests:
make test
-
Build a man page and install esh:
make install prefix=/usr/local DESTDIR=/
or just copy
esh
whether you want, it’s a plain shell script.
Read man page esh(1).
http {
access_log <%= $logs_dir/access.log %> main;
resolver <%= $(sed -En 's/^nameserver ([^#]+)/\1/p' /etc/resolv.conf) %>;
<% if nginx -V 2>&1 | grep -q lua-nginx-module; then -%>
lua_package_path '<%= $(pkg-config --variable=INSTALL_LMOD lua) %>/?.lua';
<% fi -%>
<%+ ./http-common.esh %>
<%# The rest of the config is omitted %>
}
ESH template syntax is based on ERB (Embedded Ruby).
Tests and some concepts are inspired by shellcat.
This project is licensed under MIT License. For the full text of the license, see the LICENSE file.