Skip to content

Instantly share code, notes, and snippets.

$ cljsh -c '(println "=> hello")'
=> hello
$ cljsh -c '(println "=> hello")' -c '(println "=> there")'
=> hello
=> there
$ cljsh -c '"=> hi - you cannot see me"'
$ cljsh -pc '"now you can see me"'
"now you can see me"
$ cljsh -pc '(println "=> this is followed by a nil on the next line as the result from evaluating println")'
=> this is followed by a nil on the next line as the result from evaluating println
@KSCGroup
KSCGroup / session1.log
Created February 1, 2012 22:05
new project and start repls
~/tmp>lein new cljsh-test
Created new project in: /Users/franks/tmp/cljsh-test
Look over project.clj and start coding in cljsh_test/core.clj
~/tmp>cd cljsh-test/
~/tmp/cljsh-test>lein repls
Copying 1 file to /Users/franks/tmp/cljsh-test/lib
## Clojure 1.3.0 - "lein-repls" console and server started on project "cljsh-test 1.0.0-SNAPSHOT" (pid/host/port:42914/localhost/30927) ##
user=>
~/tmp>cd cljsh-test/
~/tmp/cljsh-test>cat .lein_repls
export LEIN_REPL_PORT=30927
export LEIN_REPL_PID=42907
~/tmp/cljsh-test>cljsh -c '(println "Bye World")' -e '(println "Thanks for all the fish")'
Bye World
Thanks for all the fish
~/tmp/cljsh-test>cljsh -c '(println "the current ns is:" *ns*)'
the current ns is: #<Namespace user>
~/tmp/cljsh-test>
~/tmp/cljsh-test>cljsh -c '(defn p*ns* [] (println "ns:" *ns*))'
~/tmp/cljsh-test>cljsh -c '(p*ns*)'
ns: #<Namespace user>
~/tmp/cljsh-test>cljsh -c '(ns newuser)' -c '(user/p*ns*)'
ns: #<Namespace newuser>
~/tmp/cljsh-test>cljsh -c '(user/p*ns*)'
ns: #<Namespace user>
~/tmp/cljsh-test>
## Clojure 1.3.0 - "lein-repls" console and server started on project "cljsh-test 1.0.0-SNAPSHOT" (pid/host/port:42914/localhost/30927) ##
user=>
CompilerException java.lang.RuntimeException: Unable to resolve symbol: printlnn in this context, compiling:(/var/folders/th/v9cn0zjn1830736cjqg8l9jm0000gn/T/cljsh.auwi2qgL:1)
~/tmp/cljsh-test>cljsh -c '"you cannot see me"'
~/tmp/cljsh-test>cljsh -p -c '"but now you can"'
"but now you can"
~/tmp/cljsh-test>cljsh -c '(printlnn "one n too many")'
~/tmp/cljsh-test>echo '(println "one")' > one.clj
~/tmp/cljsh-test>echo '(println "two")' > two.clj
~/tmp/cljsh-test>echo '(println "three")' > three.clj
~/tmp/cljsh-test>echo '(println "four")' > four.clj
~/tmp/cljsh-test>cat three.clj | cljsh -c '(println "one")' -f two.clj - four.clj
one
two
three
four
~/tmp/cljsh-test>
~/tmp/cljsh-test>cat > tst.cljsh <<-EOF
> #!/usr/bin/env cljsh
> (println "wow")
> (println "args are:" cljsh.core/*cljsh-command-line-args*)
> EOF
~/tmp/cljsh-test>chmod +x tst.cljsh
~/tmp/cljsh-test>./tst.cljsh -all -my args
wow
args are: -all -my args
~/tmp/cljsh-test>
~/tmp/cljsh-test>cat <<"EOCLJ" > upper.cljsh
> #!/usr/bin/env cljsh -t
> (require 'clojure.string)
> (doseq [line (line-seq (java.io.BufferedReader. *in*))]
> (prn (clojure.string/upper-case line)))
> (.close *in*)
> EOCLJ
~/tmp/cljsh-test>chmod +x upper.cljsh
~/tmp/cljsh-test>echo "down2up2down" | ./upper.cljsh
"DOWN2UP2DOWN"
@KSCGroup
KSCGroup / cljsh-test.log
Created February 16, 2012 05:19
Logfile from running cljsh-test.sh with cljsh 1.9.4, lein-repls-1.9.4-SNAPSHOT on LUBUNTU 11.10
# cljsh-test.sh is a bash shell script that tests most non-interactive use cases for cljsh.
# Use the following command to capture the annotated output of this script in a log-file
# ./cljsh-test.sh > cljsh-test.log 2>&1
# all clojure scripts are passed to the "lein repl" server over the network/loopback
# for eval, and the output is brought back to stdout.
# cljsh -h will give help info and does some basic diagnostics