Skip to content

Add ShellForEach method for running per-line commands via the system shell - #246

Open
ChrisJr404 wants to merge 1 commit into
bitfield:masterfrom
ChrisJr404:shell-for-each
Open

Add ShellForEach method for running per-line commands via the system shell#246
ChrisJr404 wants to merge 1 commit into
bitfield:masterfrom
ChrisJr404:shell-for-each

Conversation

@ChrisJr404

Copy link
Copy Markdown

Following on from the discussion in #184, this adds ShellForEach, the per-line companion to the new Shell method.

ExecForEach splits each rendered command with shell.Fields, so a template value containing spaces gets broken up into separate arguments (the touch {{.}} on a filename with spaces problem in that issue). ShellForEach passes each rendered line to the system shell instead, so you can quote the value and let the shell deal with it:

script.ListFiles("*").ShellForEach("touch '{{.}}'").Wait()

Under the hood it runs each line through sh -c (cmd /C on Windows) the same way Shell does, and the error handling, environment, and context behaviour all match ExecForEach. Added the docs, an example, and tests including the quoted-argument case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant