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*

4
  • Thank you for clearing why my code didn't work but there's one more problem that I would like you to look into. I have updated my question after reading your answer, please have a look. Commented Jul 28, 2017 at 22:33
  • 1
    @GypsyCosmonaut, see edit that stresses the fact that cat doesn't touch its fd 3, so there's no point trying to make it point to anything. Commented Jul 28, 2017 at 22:36
  • There's one more problem, updated my question again, please have a look. Commented Jul 28, 2017 at 23:05
  • 1
    @GypsyCosmonaut, redirections are processed from left to right. in cat file 1>&3 3> ofile you're redirecting fd 1 to whatever resource was open on fd 3 (if there was a exec 3<> ./tmp before, then that will be that) and then fd 3 to ofile. So we have 1 goes ./tmp, 3 goes to ofile. cat doesn't do anything with its fd 3, so all you get is an empty ofile because it was open with truncation and nothing was ever written to it. Commented Jul 28, 2017 at 23:34