Code block redirection refers to redirecting standard or standard output to a file within a block of code, or leaving the default state outside of a block of code, in other words, code block redirection refers to the redirection of standard input or standard output only within the code block. A code block that can be redirected is a while, a until, a for, or a if/then, or even a function.
While redirection
#! /bin/bash
ls/etc> logs
While ["$filename"! = "RC.D"]
Do
Read filename
Let "count=count+1"
Done < logs #while代码块重定向输入
#测试代码块外部的标准输入是否重定向
echo "Pls, input data:"
Read Test
echo "$test"
The redirect input for the for code block is similar
if [condition]
Then
......
......
Else
......
Fi < filename
Code block redirection increases the flexibility of the shell to a certain extent, allowing a piece of code to handle a file conveniently.