Logically, the concept of an EOF is generated by the I/O handler. An EOF signal usually has nothing to do with the data being handled.
The only way to "send an EOF" is to cause the reader to report that there is nothing to read in response to a request to read something.
Consider the following code where function Hi relays stdin until EOF and is used to replay the output of an echo command:
Hi() {
while IFS= read -r -d $'\n' || [[ "$REPLY" ]]; do
echo "Hi: $REPLY"
done }
Hi < <(echo Hello)
Hi: Hello
- <(command) causes bash to create a pipe (which is conceptually a file) from the output of the command supplied.
- <(command) replaces itself with the unique filename of the pipe whose physical name gets echoed if you say:
echo <(echo Hi)
/dev/fd/63
Therefore, <(command) creates a file from its stdout and every file may have a logical EOF where its reader knows that no more data is available due to a physical end of data.
The pipe will be held open for as long as the command inside <() remains executing, holding the pipe open. When the <(command) finishes, the input end of the pipe is closed.
The bash read statement exits with error code 1 when it sees an EOF, which according to ilkkachu, is a successful system read() of zero bytes because that is what happens when there is no more data to read from a file.
The system read() call can hang without returning for as long as the reader of the file is still an active process. A timeout avoids forever hang. Physical drive startup and other connections can be very slow. Assuming an EOF due to timeout would be both slow and prone to error. Successful system read() of zero bytes=EOF.
while IFS= read -r -d $'\n' || [[ "$REPLY" ]]; do
The || (logical OR) test exists to handle the case when the file does not end with a carriage return. According to -d, the bash read will successfully return when it reads a carriage return. Bash read will fail with code 1 even if data was successfully read because failure, exit with non-zero code 1, is how bash read relays EOF.
Any program which relays information from an input to an output can choose to react to information it sees in its data stream.
The console tty (now pty or psuedo termimal) line reader/editor (ReadLine) reacts to many characters and escape sequences it reads from the keyboard which gives them their special meaning. For example: Control-H performs a backspace and Control-D sends an EOF signal (what it calls EOT or End Of Transmission) while the tty itself remains open and can send further information given another read.
/dev/null
or any other source) actually important for you for trying to complete some concrete task? And what is that task? – ilkkachu Sep 21 '21 at 18:07EOF
and wanted to make some practice about it. – BowPark Sep 21 '21 at 18:16