Mike Meyer wrote:
Is there any way to tell if inside a .clj file if it was invoked as a
script by clojure.main, vs. being loaded for use elsewhere?
Use a shebang line that calls a wrapper script, e.g. clj-script, that
passes a command-line arg to tell the code it's being run as a script.
$ ls
clj-script example.clj
$ cat clj-script
#!/bin/bash
clj "$@" --script
$ cat example.clj
#!/usr/bin/env clj-script
(ns example)
(println
(if *command-line-args*
"I am a script."
"I am not a script."))
$ PATH="$PWD:$PATH" ./example.clj
I am a script.
$ repl
Clojure 1.2.0-master-SNAPSHOT
user=> (use 'example)
I am not a script.
nil
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en