Skip to main content
deleted 121 characters in body
Source Link
the_velour_fog
  • 12.8k
  • 17
  • 74
  • 115

There are alot of documents and discussion around the file descriptors of shells and how those file descriptors can be manipulated for redirection etc.
My question is, when a shell command is an external program, like rsync, cat, curl etc, do those commands have file descriptors in the same way the shell does?
To give a concrete example, if I run this command at a terminal prompt

% cat << EOF | php <?php echo "hello". PHP_EOL; echo "another line" . PHP_EOL; EOF 

I'm assuming the contents of this heredoc are being fed to STDIN, but of which process? the shell, or does cat have a file descriptor 0 and the contents of the heredoc are being fed to cat's fd0 directly?

Even the Wikipedia file descriptor article doesn't seem to explain it.

There are alot of documents and discussion around the file descriptors of shells and how those file descriptors can be manipulated for redirection etc.
My question is, when a shell command is an external program, like rsync, cat, curl etc, do those commands have file descriptors in the same way the shell does?
To give a concrete example, if I run this command at a terminal prompt

% cat << EOF | php <?php echo "hello". PHP_EOL; echo "another line" . PHP_EOL; EOF 

I'm assuming the contents of this heredoc are being fed to STDIN, but of which process? the shell, or does cat have a file descriptor 0 and the contents of the heredoc are being fed to cat's fd0 directly?

Even the Wikipedia file descriptor article doesn't seem to explain it.

There are alot of documents and discussion around the file descriptors of shells and how those file descriptors can be manipulated for redirection etc.
My question is, when a shell command is an external program, like rsync, cat, curl etc, do those commands have file descriptors in the same way the shell does?
To give a concrete example, if I run this command at a terminal prompt

% cat << EOF | php <?php echo "hello". PHP_EOL; echo "another line" . PHP_EOL; EOF 

I'm assuming the contents of this heredoc are being fed to STDIN, but of which process? the shell, or does cat have a file descriptor 0 and the contents of the heredoc are being fed to cat's fd0 directly?

Source Link
the_velour_fog
  • 12.8k
  • 17
  • 74
  • 115

When a shell executes an external command/program - does that program have file descriptors?

There are alot of documents and discussion around the file descriptors of shells and how those file descriptors can be manipulated for redirection etc.
My question is, when a shell command is an external program, like rsync, cat, curl etc, do those commands have file descriptors in the same way the shell does?
To give a concrete example, if I run this command at a terminal prompt

% cat << EOF | php <?php echo "hello". PHP_EOL; echo "another line" . PHP_EOL; EOF 

I'm assuming the contents of this heredoc are being fed to STDIN, but of which process? the shell, or does cat have a file descriptor 0 and the contents of the heredoc are being fed to cat's fd0 directly?

Even the Wikipedia file descriptor article doesn't seem to explain it.