cat < file.txt
Who is the responsible of reading the file ?
Is the shell reads the open and read the file then write its content to the standard input of the command ?
catio-redirectionshell
cat < file.txt
Who is the responsible of reading the file ?
Is the shell reads the open and read the file then write its content to the standard input of the command ?
Best Answer
For the shell command
cat <file.txt
:<
causes the shell to openfile.txt
for reading.cat
command, with its standard input connected tofile.txt
.cat
command reads from its standard input (sofile.txt
) and copies the content to its standard output.So the shell is the one opening the file, but the
cat
command is the one reading the data.You can observe what is going on by listing the system calls performed by the shell and its subprocesses. On Linux:
(22702 is the parent shell process, 22703 is the child
cat
)The shell command
cat file.txt
works differently.cat
command, passing it one parameter, namelyfile.txt
.cat
program opensfile.txt
for reading.cat
command reads fromfile.txt
and copies the content to its standard output.