Multi-line shebangs in Clojure?

Purpose: Create a Clojure script that runs as -mainwhen running ./script.clj.

The closest I got

#!/bin/bash
#(comment
exec clj -m `basename $0 .clj` ${1+"$@"}
exit
#)
(defn -main [args]
   (println args))

But Clojure does not allow non-Lisp code inside multline comments, and Clojure does not have Common Lisps syntax #| ... |#.

+5
source share
2 answers

The syntax is unclear, but it works. From Wikibooks .

$ ./hello.clj Fred
Hello Fred!

":";exec clj -m `basename $0 .clj` ${1+"$@"}
":";exit

(ns hello
    (:gen-class))

(defn -main
    [greetee]
    (println (str "Hello " greetee "!")))
+6
source

As the Clojure CLI became available, use

#! /usr/bin/env clj

(println "Hello World!")
0
source

All Articles