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
Output:
foo
foo
foo
All these cats display the content of /dev/fd/3. But /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
exec 3<"a.txt",/dev/fd/3is always a symlink toa.txt.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: