bash for stdin 1

bash for stdin

while read line ; do  echo "$line" ; done < "${1:-/dev/stdin}"

Here is what the above code is Doing:
1. The first line is a shebang. It tells the shell what program to use to interpret the script.
2. The second line is a comment. It's ignored by the shell.
3. The third line is a while loop. It reads a line from the file, and then prints it.
4. The fourth line is a redirection. It tells the shell to read from the file given as the first argument to the script. If no argument is given, it reads from standard input.

Similar Posts