Redirection of Linux shell code blocks

Source: Internet
Author: User

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.