As described here, redirections use open()
to write to a file. There's an inner (?) file descriptor created in the shell, and then used when needed.
Is the inner descriptor created for the whole duration of the script or the shell lifetime? Is it destroyed after some time, a number of operations, etc?
I mean in particular file descriptors for the files that the shell itself opens for its builtins' operations. Is the descriptor created and the file opened for each operation? How long are they kept? Example:
#!/bin/bash
>>x echo something
...do many other things not related to the file x
>>x echo something more
Is the first descriptor instance kept until the second operation?
What about the shell I use in in a terminal? I sometimes keep one session open for days, maybe even weeks. Does it still keep the descriptors for all the files I operated on with shell built-ins?