0

What does the shell command

exec 5>>foobar.txt

do? I can't google it for obvious reasons, and otherwise not sure where to start looking.

2
  • Why was this question down voted? I found it quite useful.
    – MJ Walsh
    Apr 4, 2019 at 17:01
  • @MJWalsh gave it an upvote as I find it useful as well May 21, 2020 at 18:27

2 Answers 2

0

As others have said, it opens a file descriptor to append to the named file.

You would use this file descriptor like this:

echo "hello world" >&5
date >&5
while read line; do some_transformation; done < input_file >&5
3

The command in question redirects file descriptor 5 to a file foobar.txt.

As for "where to start looking" - this answer is a very good starting point.

1
  • 2
    To be more precise, a new shell is created to replace the current shell, but with any writes to file descriptor 5 appended to a file named foobar.txt in the current directory. Any program waiting for completion of the shell will wait for the new shell and receive its eventual exit status.
    – AFH
    Mar 11, 2016 at 12:56

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .