Skip to content
This repository has been archived by the owner on Nov 14, 2020. It is now read-only.

Adding exec function #28

Closed
wants to merge 1 commit into from
Closed

Adding exec function #28

wants to merge 1 commit into from

Conversation

adereth
Copy link

@adereth adereth commented Dec 5, 2013

I'm trying to port a few bash scripts to gherkin. I've got a few that exec at the end and I couldn't come up with a way of doing it besides adding a primitive function.

@alandipert
Copy link
Owner

Thanks! Interop is basically anything-goes until #23 is in, however with the existing sh! you can implement exec like this:

(def exec
  (fn (cmd)
    (sh! (str "exec " cmd))))

Also, per your earlier IRC message, and as of 20c70fb and cceee79, a function for matching regexes can be implemented like this:

(def re-matches?
  (fn (re s)
    (sh! (str "[[ '" s "' =~ " re " ]]"))))

(re-matches? "^he.*$" "hello") ;=> t
(re-matches? "^he.*$" "foo") ;=> nil

@alandipert alandipert closed this Dec 5, 2013
@adereth
Copy link
Author

adereth commented Dec 6, 2013

Thanks! It wasn't clear to me that I could just use bash syntax in the arguments to sh!... I'm just so conditioned to not being able to use even simple bashisms when creating commands to be construct a Process on the JVM that it didn't even occur to me.

@alandipert
Copy link
Owner

Glad to help. sh! maybe isn't properly named - it's closer to ClojureScript's js* in operation in that its argument is evaluated by bash and not necessarily shelled to.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants