Just to add to @jw013's fine answer, it may help to realise that it's the same as
{
cat -n
cat -n
} < infile
< file
being short for 0< file
, that is use file descriptor 0 instead of 3.
And just to confuse the matter a little, this version:
exec 3< infile
cat -n /dev/fd/3
cat -n /dev/fd/3
Behaves differently depending on the OS you run it in and the type of infile
(regular file vs pipe vs device...)
On Solaris and most commercial Unices, an open("/dev/fd/3")
is more or less equivalent to a dup(3)
(so < /dev/fd/3
is about the same as <&3
), while on Linux, for regular files, /dev/fd/3
is implemented as a symlink to the original file, so open("/dev/fd/3")
opens it anew from the start (and possibly with different flags from the fd 3).