This is a Linux-specific question.
The bash script is:
echo foo > "a.txt" exec 3<"a.txt" cat /dev/fd/3 cat /dev/fd/3 cat /dev/fd/3
foo foo foo
cats display the content of
/dev/fd/3 is simply a symlink to
a.txt. That explains the behavior but I don't know if it's guaranteed (and if so, by what) that:
When you run
/dev/fd/3is always a symlink to
Every time you open and read from
/dev/fd/3, it returns the entire body.
There is an answer to a similar but not entirely same question: