TAG ARCHIVE: bash
GNU Bash
Posted on Oct 18, 2013 14:35PM
WordBash is a Bash Shell Script
WordBash is written, if you do not already know, in Bash, the GNU Bourne-Again SHell. All content is generated by a shell script. All comments are parsed, stored and displayed by Bash. And when I say the code is written in Bash, I mean (with only one exception explained later): No SED. No AWK. No TR. Just 100% Bash.
It has been tested with Linux, Mac OS-X and Windows/Cygwin. Bash at least 3.2 is required.
These posts will describe WordBash in detail, and make some claims about it. Ultimately though, of course, the code gets the last word.
Code is here: wordbash-1.0.3.zip and here: WordBash.
Update: July 2023
I want to emphasize what I mean by 100% Bash.
No doubt you have searched for "how to do [something] in Bash" (or seen other
people doing that) and the "answer" was actually how to do it with a "textutil".
(Or a GNU Textutil, Fileutil, Shellutil, or Binutil.)
How to do something in sed is not how to do something in bash.
Same goes for pattern matching (or regular expressions) "in Bash". If all
the examples one supplies are with ls, that's file globbing; or with grep, that's using grep.
I wish people would get that.

Posted on Jan 6, 2014 11:12AM
A Web Template Non-Engine
I have seen it written that templates cannot be implemented in Bash. Well, "The impossible takes a little longer," someone once said. But it actually did not take me all that long to create a true web template API of about 100 lines.
First, there exists global site data such as this:
bash code
sitebase=${SCRIPT_NAME%/*}
sitehost="http://$HTTP_HOST$REQUEST_URI"
sitedesc="Syntagmatic Personal Publishing Platform"
sitename="WordBash"
sitetitle="The first WordBash site"
A basic template, which comes from a file, is like this:
text='<!DOCTYPE html>
<title>$sitetitle</title>
<link rel="stylesheet" type="text/css" href="$sitebase/style.css">
<header>
<h1><a href="$sitehost" title="$sitetitle">$sitename</a></h1>
<h2>$sitetitle</h2>
</header>'
Just what is a this for anyway?
It is to display the HTML with the variable references replaced by the actual data during run-time. Doing so takes what is known as an "engine". Why? It generally takes a lot of code to do it. A lot of code.
It can be done in Bash like this:
Continue reading →

Posted on Feb 1, 2014 4:35PM
This post addresses Bash performance by demonstrating code to accomplish three things:
- stripping HTML
- decoding POST data
- simple post markup
I think you will find it enlightening (well, I did).
Stripping HTML Tags
Stripping tags is straight forward and uses a single state flag:
bash code
# strip tags
st() {
n=${#data}
t=0
r=
for (( i=0; i<$n; i++ )); do
if [[ ${data:$i:1} == ">" ]]; then t=0; continue; fi
if [[ $t == 1 ]]; then continue; fi
if [[ ${data:$i:1} == "<" ]]; then t=1; continue; fi
r+=${data:$i:1}
done
data=$r
}
That, though, only demonstrates that expanding a string one character at a time is slow. Sometimes case is used for parsing data, so let's give it a try:
Continue reading →