Welcome! Please see the About page for a little more info on how this works.

+8 votes
in Tools by
edited by

Sometimes quoting strings or shell invocations can be a bit verbose or clumsy in the shell when passing arguments to exec functions (-X) because those arguments have to be quoted with an extra layer since they are parsed as EDN.

This example was recently posted in Slack:

clojure -X:bench :json "$(my_json_producing_cmd --blah)"

and it turned out nearly impossible to pass the JSON as an argument.

Having a way to bypass EDN parsing for such arguments could alleviate that problem.

One possible convention could be to use a leading character which would otherwise be invalid in EDN, such as the / sign:

clojure -X:bench :json /"$(my_json_producing_cmd --blah)"

Alternative approaches:

  • Use metadata on the function to opt out of processing: that would change the parsing behavior at the implementation side, e.g.:

      (defn foo
        {:tools.deps/exec-skip-edn-read #{:a}} 
        [{:keys [a b c]}]
  • Add something to deps.edn config in :exec-args: that would only change the behavior for consumers

Extra things to consider:

  • The convention should play well with both bash, cmd.exe and Powershell and not mean anything special in the syntax of those shells. I tried / in these shells and this does not seem to interfere.

After experimentation I found that / might work better than @ since @ has a special meaning in powershell:

bb -e "*command-line-args*" /foo @bar

Also @ often means: slurp contents from file and inline that content as arg.

2 Answers

0 votes
0 votes

I have a potential solution for this, but in the form of a library:


Perhaps it can help inform the array of possible solutions.

I'm satisfied with using babashka.cli as a solution to this problem, so if core isn't interested in pursuing this further, I think this could be closed.