curl -s https://chr15m.github.io/flk/flk > flk && chmod 755 flk ./flk
Examples | Reference | FAQ | make-a-lisp
$ echo '(println "Hello world!") (println "Hostname:" (sh* "hostname")))' > example.clj $ ./flk example.clj Hello world! Hostname: diziet
Now you can use a humble LISP to do Bash things. Bash as a scripting language has many edges, but it is everywhere. Fleck attempts to round off the edges.
Fleck runs on Bash 4 and higher.
Almost all of this code is from the make-a-LISP project. All I've done is put together a simple Makefile to package it up into an easily deployable single-file bash script.
A list of variables, macros and functions that are present in Fleck.
This is the set of built-ins from the make-a-lisp project.
These more or less work but are generally more limited in functionality than their Clojure equivalents.
For example the addition function
(+) can only add two integers at a time.
*ARGV*- list of arguments passed on the command line.
These are wrappers around the limited make-a-lisp versions and are much more limited than the Clojure equivalents.
These functions are pulled from a selection of
These functions are hand crafted Fleck specials designed to make common shell scripting tasks easier.
(str-replace STRING FIND REPLACE)- Replace all occurrences of the string
STRINGwith the string
(str-split STRING SPLIT-CHARACTER)- Split
STRINGinto a list of strings on the single characters
(dc OPERATOR ARRAY-OF-NUMBERS)- Wraps the
dccommand to do decimal math. E.g.
(dc '+ [1 2 3])yeilds
(env [KEY] [VALUE])- Returns a
hash-mapof environment variables. Returns the value of
KEYif present. Sets the value of
VALif the latter is present.
(sh* COMMAND)- Run arbitrary bash strings and return the stdout result.
(env [KEY] [VALUE])- See above section.
For examples of writing your own Fleck functions in Bash see src/extras.sh.
Functions should set the special return value
r and use Fleck type casting functions like
_string to wrap the result in a reference.
Internal Fleck functions such as
_string automatically do this and can be used bare.
_fref to make your function available to the Fleck namespace e.g.
_fref "my-bash-function" _my_bash_function.
You can make a pure bash script from your Fleck script by bundling your script and Fleck together into a new script.
Say you have a Fleck script called
wow.clj, you can bundle it as follows:
make DEST=wow INSERT=./wow.clj NOREPL=1
This will produce a new standalone script called
wow with Fleck +
wow.clj bundled together.
When you run
wow the embedded
wow.clj will be run by the embedded Fleck.
Think of this as homoiconic Bash rather than Clojure, and code as if you're in Bash.
Will my favourite piece of Clojure run in this?
No, it's bash.
How do I access command line arguments?
Use the special global list
How do I access and modify environment variables?
How can I execute a one-liner of Fleck code?
Either of these methods will work:
flk <<< '(println "hi")' echo '(println "hi")' | flk
Why can't I add more than 2 numbers together?
It's bash. Try the
(dc '+ [1 2 3 4])
Where are the floating point numbers?
It's bash. Try the
dc function for decimals:
(dc '* [8.2 3.5])
dc is set to keep four fractional digits in its results.
How do I cast a string to a number?
(read-str "42") but also Bash doesn't care and
(+ "1" 1) will yeild
Why can't I iterate on a string?
How do I do destructuring?
Can I use anything as a
Seems unlikely. Better stick to strings.
This is even slower than Python!
PS That is not actually a question.
Haven't I seen this before somewhere?
You're probably thinking of Gherkin, the original Clojure-like LISP in Bash by Alan Dipert. Gherkin helped kick off the make-a-lisp revolution.
Why is it called Fleck?
36k and running on any machine with Bash 4, the name seemed appropriate.
fleck n. A tiny mark or spot. n. A small bit or flake.