Skip to content
Simple templating engine based on shell.
Shell Makefile
Branch: master
Clone or download
Latest commit 159ddfe Jul 31, 2019


ESH – Embedded SHell

Build Status

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 and sed (e.g. from Busybox, GNU, …)

  • (Asciidoctor to build a man page)


Alpine Linux

Install package esh from the Alpine’s community repository:

apk add esh
This package is in Alpine stable since v3.7. You can also install it from edge (unstable) branch.


dnf install esh


Install package esh from my repository on openSUSE Build Service:

zypper addrepo
zypper refresh
zypper install esh


You can add esh as a submodule into your repository or download it on demand, e.g.:

wget \
    && echo 'fe030e23fc1383780d08128eecf322257cec743b  esh' | sha1sum -c \
    || exit 1


  1. Download and unpack release tarball:

    tar -xzf esh-0.3.0.tar.gz
    cd esh-0.3.0
  2. Run tests:

    make test
  3. 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.

You can’t perform that action at this time.