In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article will explain in detail how to achieve input and output functions on the shell command line. The editor thinks it is very practical, so I share it with you as a reference. I hope you can get something after reading this article.
Standard input / output and redirection, Linux distribution Fedora Core Linux, and Red Hat's original Red Hat Linux development team will continue to be involved in the development of this release.
Standard input and output
We know that when you execute a shell command line, you usually open three standard files automatically, namely, the standard input file (stdin), which usually corresponds to the terminal's keyboard; the standard output file (stdout) and the standard error output file (stderr), both of which correspond to the terminal screen. The process will get the input data from the standard input file, output the normal output data to the standard output file, and send the error information to the standard error file.
Let's take the cat command as an example. The function of the cat command is to read data from the file given by the shell command line and send the data directly to standard output. To use the following command:
Cat config will display the contents of the file config on the screen in turn. However, if cat has no arguments on the shell command line, it reads the data from the standard input and sends it to the standard output. For example:
$cat
Hello world
Hello world
Bye
Bye
Each line entered by the user is immediately output to the screen by the cat command. In another example, the command sort reads the file body by line (when the file name is not given on the shell command line, it is read from standard input), sorts it, and sends the results to standard output. The following example reads a purchase order from standard input and sorts it.
$sort
Bananas
Carrots
Apples
Bananas
Carrots
Then we got the sorted purchase order on the screen. There are the following problems in using the standard input / output file directly: when the input data is input from the terminal, the data entered by the user who takes a long time to input can only be used once. The next time you want to use the data, you have to re-enter it. And when entering on the terminal, it is not very convenient to modify it if the input is wrong. The information output to the terminal screen can only be seen and not moved. We cannot do more processing on this output, such as further processing the output as input to another command. In order to solve the above problems, Linux system introduces two other mechanisms for input and output transmission, namely input / output redirection and pipeline.
Input redirection
Input redirection refers to redirecting the standard input of a command (or executable program) to a specified file. That is, the input can come not from the keyboard, but from a specified file. Therefore, input redirection is mainly used to change the input source of a command, especially those that require a lot of input. For example, the command wc counts the number of lines, words, and characters contained in the file. If you type only on the shell command line:
$wc
Wc will wait for the user to tell it what to count, and then shell will be dead. All the text typed from the keyboard will appear on the screen, but there will be no results until wc writes the command results on the screen by pressing < ctrl+d >. If you give a file name as an argument to the wc command, as shown in the following example, wc returns the number of lines, words, and characters contained in the file.
$wc / etc/passwd
20 23 726 / etc/passwd another way to pass the contents of the / etc/passwd file to the wc command is to redirect wc input. The general form of input redirection is: command delim
In
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.