This is still way under development and verification, but the main idea here is to be able to write a plain text document with shell code enclosed between $[
and ]
. And then be able to compile it into a working shell script that prints everything verbatim using printf
and the code between the tags gets executed in the same subshell.
There are similar examples that but not quite the same like bash-tbl, spp, sempl, and another snippet I can't find right now.
esht requires one or more filenames as arguments, the first will be considered the source file. If a second filename is provided it will be considered as the output file and will be created, or overwritted if it already exists. If no output file specified, esht will print to the standard output.
Given a file source.html.esht
with the following content:
$[ # define a user function
table_element() {
echo "<td bgcolor=\"$1\">$1</td>"
}
]
<html>
<body>
<table border=1><tr>
$[ for a in Red Blue Yellow Cyan; do ]
$[ table_element $a ]
$[ done ]
</tr></table>
</body>
</html>
Running ./esht source.html.esht output.sh
will generate the file output.sh
with the following code:
# define a user function
table_element() {
echo "<td bgcolor=\"$1\">$1</td>"
}
printf '\n<html>\n\t<body>\n<table border=1><tr>\n'
for a in Red Blue Yellow Cyan; do
printf '\n '
table_element $a
printf '\n '
done
printf '\n</tr></table>\n</body>\n</html>\n'
Which in turn can be sourced by running . output.sh
to get the html output:
<html>
<body>
<table border=1><tr>
<td bgcolor="Red">Red</td>
<td bgcolor="Blue">Blue</td>
<td bgcolor="Yellow">Yellow</td>
<td bgcolor="Cyan">Cyan</td>
</tr></table>
</body>
</html>
The same result from above can can also be produced by using -x
option.
-x
option to automatically execute the generated script-u
option to automatically update esht-e
option to include environmental variablesThis project is licensed under The Unlicense