In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
How to understand the angle brackets in Bash, many novices are not very clear about this, in order to help you solve this problem, the following editor will explain for you in detail, people with this need can come to learn, I hope you can gain something.
Introduce angle brackets for beginners.
Bash includes many important commands such as ls, cd, and mv, as well as many useful tools such as grep, awk, and sed. But in addition, there are many punctuation marks in Bash that can act as glue, such as dots (.), commas (,), parentheses (), quotation marks (") and so on. Let's take a look at the angle brackets () that can be used for data conversion and transfer.
Transfer data
If you know anything about other programming languages, you will know that angle brackets are generally used as logical operators to compare the size relationship between two values. If you also write HTML, angle brackets, as part of various tags, will not be unfamiliar to you.
In the shell scripting language, angle brackets can move data from one place to another. For example, you can store data in a file like this:
Ls > dir_content.txt
In the above example, the > symbol tells shell to write the output of the ls command to dir_content.txt instead of displaying it directly on the command line. It is important to note that if the dir_content.txt file does not exist, Bash will be created for you, but if dir_content.txt is an existing non-empty file, its contents will be overwritten. So be careful before doing something like this.
You can also use > instead of >, so that the new data can be appended to the end of the file without overwriting the existing data in the file. For example:
Ls $HOME > dir_content.txt; wc-l dir_content.txt > > dir_content.txt
In this series of commands, you first write the contents of the home directory to the dir_content.txt file, then use wc-l to calculate the number of lines in the dir_content.txt file (that is, the number of files in the home directory) and append it to the end of the dir_content.txt.
After executing the above command on my machine, the content of the dir_content.txt will look like this:
ApplicationsbincloudDesktopDocumentsDownloadsGamesISOsliblogsMusicOpenSCADPicturesPublicTemplatestest_dirVideos17 dir_content.txt
You can understand > and > as arrows. Of course, the direction of this arrow can also be reversed. For example, some actors from Coen brothers (LCTT Brothers, an American film director group) and the number of times they starred in movies are saved in the CBActors file, like this:
John Goodman 5John Turturro 3George Clooney 2Frances McDormand 6Steve Buscemi 5Jon Polito 4Tony Shalhoub 3James Gandolfini 1
You can execute the following command:
Sort
< CBActorsFrances McDormand 6 # 你会得到这样的输出George Clooney 2James Gandolfini 1John Goodman 5John Turturro 3Jon Polito 4Steve Buscemi 5Tony Shalhoub 3 就可以使用 sort 命令将这个列表按照字母顺序输出。但是,sort 命令本来就可以接受传入一个文件,因此在这里使用 filmsfirst.txt; done < CBActors 上面这串命令写在多行中可能会比较易读: while read name surname films;\ do echo $films $name $surname >> filmsfirst;\ done
< CBActors 下面来分析一下这些命令做了什么: while …; do … done 是一个循环结构。当 while 后面的条件成立时,do 和 done 之间的部分会一直重复执行; read 语句会按行读入内容。read 会从标准输入中持续读入,直到没有内容可读入; CBActors 文件的内容会通过 >Filmsfirst;\ to rearrange the order of several fields and store them in the filmfirst file.
When you are done, look at the filmsfirst file and the content will look like this:
5 John Goodman3 John Turturro2 George Clooney6 Frances McDormand5 Steve Buscemi4 Jon Polito3 Tony Shalhoub1 James Gandolfini
Use the sort command again at this point:
Sort-r filmsfirst
You can see that Coens's favorite actor is Frances McDormand. (the-r parameter indicates descending order, so McDormand comes first)
Is it helpful for you to read the above content? If you want to know more about the relevant knowledge or read more related articles, please follow the industry information channel, thank you for your support.
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.