... - recurring pattern: the file descriptor to the tmpfile is dup'ed to fd N, where N is equal to the one in /dev/fd/N, the device file specified to be opened by the child. @@ strace -ff -e open,close,unlink,read,write,execve,dup2 -- bash ./here_doc_disx.sh # here_doc_disx.sh: # cat /dev/fd/0 <<\EOF # Hello, world! # EOF execve("/usr/bin/bash", ["bash", "./here_doc_disx.sh"], 0x7ffcaa1b6388 /* 63 vars */) = 0 open("/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3 close(3) = 0 open("/lib64/libtinfo.so.6", O_RDONLY|O_CLOEXEC) = 3 read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\300\331\0\0\0\0\0\0"..., 832) = 832 close(3) = 0 open("/lib64/libdl.so.2", O_RDONLY|O_CLOEXEC) = 3 read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\240\r\0\0\0\0\0\0"..., 832) = 832 close(3) = 0 open("/lib64/libc.so.6", O_RDONLY|O_CLOEXEC) = 3 read(3, "\177ELF\2\1\1\3\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0P\10\2\0\0\0\0\0"..., 832) = 832 close(3) = 0 open("/dev/tty", O_RDWR|O_NONBLOCK) = 3 close(3) = 0 open("/usr/lib/locale/locale-archive", O_RDONLY|O_CLOEXEC) = 3 close(3) = 0 open("/usr/lib64/gconv/gconv-modules.cache", O_RDONLY) = 3 close(3) = 0 open("./here_doc_disx.sh", O_RDONLY) = 3 read(3, "cat /dev/fd/0 <<\\EOF\nHello, worl"..., 80) = 39 dup2(3, 255) = 255 close(3) = 0 read(255, "cat /dev/fd/0 <<\\EOF\nHello, worl"..., 39) = 39 strace: Process 1681 attached [pid 1681] close(255) = 0 [pid 1681] open("/tmp/sh-thd-932991243", O_WRONLY|O_CREAT|O_EXCL|O_TRUNC, 0600) = 3 [pid 1681] write(3, "Hello, world!\n", 14) = 14 [pid 1681] open("/tmp/sh-thd-932991243", O_RDONLY) = 4 [pid 1681] close(3) = 0 [pid 1681] unlink("/tmp/sh-thd-932991243") = 0 [pid 1681] dup2(4, 0) = 0 [pid 1681] close(4) = 0 [pid 1681] execve("/usr/bin/cat", ["cat", "/dev/fd/0"], 0x75ebd70e90 /* 62 vars */) = 0 [pid 1681] open("/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3 [pid 1681] close(3) = 0 [pid 1681] open("/lib64/libc.so.6", O_RDONLY|O_CLOEXEC) = 3 [pid 1681] read(3, "\177ELF\2\1\1\3\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0P\10\2\0\0\0\0\0"..., 832) = 832 [pid 1681] close(3) = 0 [pid 1681] open("/usr/lib/locale/locale-archive", O_RDONLY|O_CLOEXEC) = 3 [pid 1681] close(3) = 0 [pid 1681] open("/dev/fd/0", O_RDONLY) = 3 [pid 1681] read(3, "Hello, world!\n", 131072) = 14 [pid 1681] write(1, "Hello, world!\n", 14) = 14 Hello, world! [pid 1681] read(3, "", 131072) = 0 [pid 1681] close(3) = 0 [pid 1681] close(1) = 0 [pid 1681] close(2) = 0 [pid 1681] +++ exited with 0 +++ --- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=1681, si_uid=1000, si_status=0, si_utime=0, si_stime=0} --- read(255, "", 39) = 0 +++ exited with 0 +++ @@ #=====