Forrest logo
back to the while tool

read:tldr:208c8

read: Read `stdin` and perform an action on every line.
$ while read line; do echo "$line"; done
try on your machine

This command is a basic while loop that reads input lines from standard input and then echoes them back. Here's a breakdown of how it works:

  1. while read line; do: This line starts the while loop. The read line command reads one line of input and stores it in the variable line. The do keyword indicates the start of the loop's body.

  2. echo "$line";: This line echoes the value of the line variable back to the standard output. The echo command is used to print the value of line. The quotes around $line ensure that any whitespace or special characters in the variable's value are preserved.

  3. done: This line marks the end of the loop. It indicates that the loop's body has finished and the loop should continue to the next iteration or exit if there are no more lines of input.

So, this command essentially reads each line of input and echoes it back to the output until there are no more input lines left.

This explanation was created by an AI. In most cases those are correct. But please always be careful and never run a command you are not sure if it is safe.
back to the while tool