That's deeply clever and a little scary. I had to call in my
bash-guru friend to pick it apart.
Because it does not start with #!, the whole file gets passed to /bin/sh
/bin/sh sees the first line starts with # and skips it as a comment,
and then goes on to run the "exec java" line. Since it's "exec",
/bin/sh never gets any farther.
The exec line sends the path of your script to Clojure, which loads
and runs the whole thing from the top. In Clojure, # does not mean a
comment, but #^ is used for metadata. So the ":shebang" part doesn't
really matter except that it starts with : so it's a Clojure keyword.
The #^ metadata form wants to be followed by something, and it this
case its a quoted vector '[...] The exec line that meant something to
/bin/sh is now seen by Clojure as a series of symbols and strings to
be stored in the vector and tagged with the :shebang metadata. ...but
nothing is done with this value, so the rest of your Clojure code gets
run unhindered.
This was apparently added to the wiki by "Digash" -- impressive!
--Chouser
Be aware that as shown, variable references, including positional ($1,
$2 etc.) local and environment will be expanded in the here-document.
If you quote the terminating symbol immediately following the "<<"
operator, the body of the here document is taken literally.
Randall Schulz
C> This was apparently added to the wiki by "Digash" -- impressive!
Thank you for explaining it so well!
Regards,
DiGash
--
,`,`,`,`,`,`,`,`,`,`,`,`,
,`,`,`,` @ `,`,`,` .com ,
, Dimitry Gashinsky ,`,`,
,`,`,`,`,`,`,`,`,`,`,`,`,
>
> Greetings
>
> I couldn't figure out how to pass command line arguments to a clojure
> script. (the usual argc, argv stuff).
> Also it would be really useful if we can have things similar to "perl
> -e '(snippet of code)'".
>
> Are there any plans to implement such things ?
Any arguments you pass to Clojure after a '--' will be available as
*command-line-args*, for example:
dudley@hiro :> java -cp clojure.jar clojure.lang.Repl -- a b c
Clojure
user=> (prn *command-line-args*)
("a" "b" "c")
Rich has said on IRC that he's not averse to having a richer command-
line interface in Clojure, but it's not something he needs or uses, so
he's not planning on adding it himself (Rich, please correct me if
I've misunderstood). If we want more advanced stuff (like "-e") we'll
have to write it.
:dudley
Yep. That was what I was looking for. That will do for the moment.
>
> Rich has said on IRC that he's not averse to having a richer command-
> line interface in Clojure, but it's not something he needs or uses, so
> he's not planning on adding it himself (Rich, please correct me if
> I've misunderstood). If we want more advanced stuff (like "-e") we'll
> have to write it.
Understood. I havn't taken a look at the implementation details at all
yet. Right now I am having too much fun rewriting my JRuby/Jython
scripts in Clojure. (I have tried ABCL with JFLI, but somehow Clojure
seems really right.)
thanks
pj