Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

13
  • Yea the sudo ruby <(echo "puts 'hello'") doesn't work. It is from this answer. The only way it worked was the way I had it in my question. I was going for a one-liner Commented Apr 16, 2021 at 22:45
  • So you're saying that if I do something like exec 1>&7-, bash will simply parse this to mean "close fd 1", and just ignores the 7 in there? But without the -, it means, redirect fd 1 to fd 7? Seems like quite the jump in reasoning, but I guess it makes sense Commented Apr 16, 2021 at 22:47
  • 1
    @smac89, oooh, right, it's /proc/$$/fd/, not /proc/self/fd/, so you're letting ruby "steal" the fd from the shell's fd list. That's... somewhat convoluted, but ok, I suppose it works. Commented Apr 16, 2021 at 22:50
  • @smac89 1>&7 would mean to fd 1 a copy of fd 7. 1>&- would close fd 1. I'm not at all sure what 1>&7- should be. Oh, should have read the manual, it moves the fd from 7 to 1. Commented Apr 16, 2021 at 22:52
  • 2
    @smac89, not quite that either. Let's take something similar to the first one. exec {ec}< <(echo "echo bye"). Say ec gets the number 9, just to pick one. Now, fd 9 is connected to the process substitution. Now, don't do anything else with $ec, just run the exec <&$ec-, same as exec 1<&9-. That says to move 9 to 1 (stdin), so now 1 is connected to the process substitution and 9 gets closed. Then the shell reads input from 1, now the process substitution. It reads echo bye, runs that, gets an end-of-file, and exits. Commented Apr 16, 2021 at 23:07