Start lein repl with commands from the terminal
Asked Answered
B

1

10

I would like to write a shell script to start a lein repl and then provide some commands while still keeping the repl running.

For example I might want to do the equivalent of:

lein repl
(dev)
(setup)

I can pipe to the repl by echo "(dev)\n(setup)" | lein repl but the repl terminates afterwards.

Is there a way to get around this or another means of starting a repl and issuing commands from a shell script?

Badinage answered 30/10, 2013 at 12:57 Comment(1)
If you don't need lein, but only clojure, you can use the -e and -r command line options.Guava
L
14
(echo "(println :hello)"; cat <&0) | lein repl

This prints the command - letting the REPL process it -, then "switches back" to stdin for input. You might have to interrupt the cat call after leaving the REPL, though.

Ln answered 30/10, 2013 at 13:35 Comment(3)
Cool trick, xsc. I use things like 2>&1 all the time, but didn't know that one.Guava
Why not just echo '(println 1)' | lein repl ?Caffeine
@AntonChikin This would cause the REPL to shut down after running the command, something the question specifically wants to avoid.Ln

© 2022 - 2024 — McMap. All rights reserved.