Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiline shebangs in Clojure?

Goal: produce a Clojure script which runs -main when run as ./script.clj.

The closest I've gotten is

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

But Clojure doesn't allow non-Lisp code inside multline comments, and Clojure doesn't have Common Lisps's #| ... |# syntax.

like image 262
mcandre Avatar asked Mar 08 '11 01:03

mcandre


1 Answers

The syntax is obscure, 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 "!")))
like image 171
mcandre Avatar answered Nov 06 '22 09:11

mcandre