rake icon indicating copy to clipboard operation
rake copied to clipboard

Feature Request: echo value of `sh` `:out` option

Open avdi opened this issue 4 years ago • 3 comments

Given the task foo, which uses the sh helper with Process.spawn-style options:

task "foo" do
  sh({ "FOO" => "BAR" }, "ls manuscript/*.md", out: "mdlist.txt")
end

Currently, running this task reveals environment variables in shell-command style, but not the output sink.

$ rake foo
FOO=BAR ls manuscript/*.md

Suggested behavior is to reveal the output sink as a simulated shell redirect:

$ rake foo
FOO=BAR ls manuscript/*.md > mdlist.txt

avdi avatar Oct 01 '20 19:10 avdi

(I'm mostly just capturing some TODOs for myself here as I find features I'd like to contribute)

avdi avatar Oct 01 '20 19:10 avdi

Does this does not work?

task "foo" do
  sh({ "FOO" => "BAR" }, "ls manuscript/*.md > mdlist.txt")
end

mblumtritt avatar Aug 05 '22 09:08 mblumtritt

Does this does not work?

task "foo" do
  sh({ "FOO" => "BAR" }, "ls manuscript/*.md > mdlist.txt")
end

There are reasons to want to avoid embedding shell syntax into tasks if we can. Once we use shell syntax ruby automatically switches to shelling out to the default shell rather than executing the process directly. Among other issues, this exposes us to more expansion surprises, differences of behavior on different systems, and commands that flat-out don't work on some platforms. It also opens up security considerations in any context where we may be interpolating info from an untrusted source. Maybe rare for Rake scripts, but possible.

Avoiding shelling out is always the safer and more predictable option. It would be nice to be able to do the safe thing and still have a reasonable echo of how to reproduce it from the command line.

avdi avatar Aug 05 '22 14:08 avdi