Shebang Script for Clojure
Shebang lines come in handy when writing and running scripts in CLIs.
With Leiningen and its plugin, Clojure can also be run with shebang script.
1. Install something
A. Install Leiningen
Firstly, we need Java:
After that, download and place lein
script in a preferred place:
We need additional permissions for running lein
:
After all things are setup correctly, we can see the version of lein
with following command:
B. Install lein-exec
We need lein-exec for executing Clojure files with ease.
Add [lein-exec "0.3.6"]
to your ~/.lein/profiles.clj
, then it will look like:
lein-exec
will be installed automatically when next time you run lein
.
2. Write the shebang line
Append following line on the first line of your script:
and add execute permission to your script:
then it will be runnable by itself:
999. Wrap-up
Clojure may not be intended to be used like this,
but in this way, it will be a lot easier to run and test in the terminal :-)