There is not much difference between these parameters (except that the file as a strict version reduces the flexibility of your program). To compare both approaches, let him check what remains of the FILE* magic entity:

Thus, in both cases, we have a FILE* object, the file descriptor fd is the gateway for the OS kernel and intranuclear infrastructure, providing access to files or user terminals that should (if libc does not have a special initializer for stdout, or the kernel specifically processes files with fd = 1).
How does bash redirection work compared to fopen() ?
When bash redirects a file:
fork() // new process is created fd = open("file", ...) // open new file close(1) // get rid of fd=1 pointing to /dev/pts device dup2(fd, 1) // make fd=1 point to opened file close(fd) // get rid of redundant fd execve("a") // now "a" will have file as its stdout // in a stdout = fdopen(1, ...)
When you open the file yourself:
fork() // new process is created execve("a") // now "a" will have file as its stdout stdout = fdopen(1, ...) my_file = fopen("file", ...) fd = open("file", ...) my_file = fdopen(fd, ...)
So, as you can see, the basic difference of bash comes down to file descriptions.
myaut source share