How to pass a vector of strings to java.shell in clojure?
I am trying to make use of (require [clojure.java.shell :refer [sh]]) to execute rsync backups in clojure. The function sh takes strings as args such as:
(sh "ls" "-las" "/home/")
However, I find myself with data arriving to sh as a vector of strings (e.g ["ls" "-las" "/home/"]) and this of course fails. This seems like what would be an extremely easy problem to solve, but I am just starting clojure (and lisp and functional programming by that matter) and I just can't seem to get this to work. How can I process the vector to pass to sh?
Any advice would be greatly appreciated.
It sounds like you need to use apply:
(apply sh arg-vector)
The apply function also pops up in other LISPs, allowing you to pass a list of arguments to a given function. In Clojure you're not limited to just lists, but any seq-able object, including vectors.