Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Request: echo value of sh :out option #364

Open
avdi opened this issue Oct 1, 2020 · 3 comments
Open

Feature Request: echo value of sh :out option #364

avdi opened this issue Oct 1, 2020 · 3 comments

Comments

@avdi
Copy link

avdi commented Oct 1, 2020

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
Copy link
Author

avdi commented Oct 1, 2020

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

@mblumtritt
Copy link

Does this does not work?

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

@avdi
Copy link
Author

avdi commented Aug 5, 2022

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.

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

No branches or pull requests

2 participants