ESH(1)
πΈ NAME πΈ
okay bestie, welcome to ESH(1) β this is esh, the simple template system based on shell, and honestly it's giving main-character energy for config files. π
β¨ SYNOPSIS β¨
esh [-d] [-o output] [-s shell] [--] file [variable ...]
esh <-h | -V>
π DESCRIPTION π
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). π¦
esh converts template file, or stdin if file is -, into a sequence of shell commands. Commands between <% and %> tags are passed as-is, everything else is escaped and prefixed with printf command. These commands are eventually evaluated using shell (unless -d is specified). β¨
π OPTIONS π
-dβ Donβt evaluate template, just dump a shell script.-ofile β Output file or-for STDOUT. Defaults to-.-sshell β Command name or path of the shell to use for template evaluation. It must not contain spaces. Defaults to/bin/sh.-hβ Show help message and exit.-Vβ Print version and exit.
π¦ ENVIRONMENT π¦
esh may be configured using the following environment variables:
ESH_AWKβ Command name of path of theawkprogram to use. It must not contain spaces. Defaults toawk.ESH_MAX_DEPTHβ Maximum include depth. Defaults to3.ESH_SHELLβ The same as-s shell.
The following extra environment variables are available inside the template and for the processes spawned by esh:
ESHβ Path of theeshinterpreter.
π EXIT STATUS π
esh exits with the exit status of shell or awk unless some error has encountered before converting the template.
0β Clean exit, no error has encountered.1β Generic error.10β Invalid usage.11β ESH syntax error.12β Include error: file not found.13β Include error: exceeded max include depth (ESH_MAX_DEPTH).
β TEMPLATE SYNTAX β
ESH has two tags for shell code, a tag for include, comments, and a way to escape tag delimiters. iykyk π
<% commands %>β Executes the commands and replaces this tag with its output on stdout.<%= values %>β Executesprintf '%s 'with the values as arguments and replaces this tag with the output (without trailing white space). values are not quoted or escaped, so all shell substitutions are applied.<%+ filename %>β Reads and converts ESH template from the filename and puts it in place of this tag. Includes are processed recursively, but the depth is limited byESH_MAX_DEPTH.
If the filename is relative, itβs resolved against the directory of the template file in which this tag resides. If the template is read from stdin, the first level includes are resolved against the current working directory. Please note that includes are processed during the conversion, not the evaluation phase, so the filename cannot be an expression or a variable!
Unlike the others, this tag must be closed on the same line, otherwise itβs a syntax error.
<%# comment %>β Removed from the final output.-%>β May be used instead of%>. It trims the following line break if used at the end of line, otherwise has no trimming effect.<%%β A literal<%when used outside of the above tags.%%>β A literal%>when used inside of the above tags.
β οΈ Opening and closing tag may not be at the same line. not me forgetting that π
Text outside a tag becomes literal text, but it is subject to any tagged shell code surrounding it. For example, text surrounded by a tagged if statement only appears in the output if the condition is true. π«Ά
π₯ EXAMPLES π₯
nginx.conf.esh
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 %>
}
To generate the resulting configuration file run:
esh -o nginx.conf nginx.conf.esh logs_dir=/var/log/nginx
π AUTHORS π
esh's author is Jakub Jirutka. πβ¨
π REPORTING BUGS π
Report bugs to the projectβs issue tracker at https://github.com/jirutka/esh/issues. pls be nice, bugs are just misunderstood features sometimes π«Ά
π SEE ALSO π
mwah π β source/version: ESH(1), date: 2022-12-13. bye bestie, go template something iconic ππ¦
π¦ where this page comes from
- alpine 3.22: esh-doc 0.3.2-r0 Β· MIT
- alpine 3.23: esh-doc 0.3.2-r0 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms