简体   繁体   English

外壳中的$(wc -l $ title_file)集合是什么意思?

[英]what does the set $(wc -l $title_file) mean in shell?

These days.i'm learning the shell script for fun.When i read the manual's example like: 这些天来,我正在学习shell脚本的乐趣。当我阅读该手册的示例时,例如:

set $(wc -l $title_file)
  num_titles=$1
  set $(wc -l $tracks_file)
  num_tracks=$1

And i have the brief understanding that the command,set,specify the $1 and set the value of $1 to the num_titles. 而且我有一个简短的了解,该命令设置,指定$ 1并将$ 1的值设置为num_titles。 But,i have no idea why use -l as the option for the command,set.And by the way,would any guy can explain the whole story of it?thx 但是,我不知道为什么使用-l作为命令set的选项。顺便说一句,任何人都可以解释它的全部故事吗?

the -l switch is counting the number of lines in the specified file(s) in your case, it is counting the number of lines in the titles file and setting it to the num_titles variable (and counting the number of lines in the file specified by the tracks_file variable and setting the value to num_track variable) -l开关正在计算您指定情况下指定文件中的行数,它正在计数标题文件中的行数并将其设置为num_titles变量(并计算指定文件中的行数通过tracks_file变量并将值设置为num_track变量)

you can simply try wc -l on the command line to see the value it prints out 您可以在命令行上简单地尝试wc -l来查看打印出的值

Firstly set sets an environment variable. 首先set设置一个环境变量。 Using the syntax set var = value or set var [n] = word as per its manpage , to view the manpage type man set . 使用语法set var = value或根据其手册页set var [n] = word来查看man set页类型man set

In this case set is using the second syntax to make $1 = $(wc -1 $titlefile) and then setting num_titles to $1 as a regular variablle because of the syntax used. 在这种情况下,set使用第二种语法使$1 = $(wc -1 $titlefile) ,然后由于使用的语法而将num_titles设置为$ 1作为常规变量。

wc is the wordcount command, and displays lines, characters and words in a file. wc是wordcount命令,可在文件中显示行,字符和单词。

wc -l tells wc to count by line as per the wc manpage, to view the manpage type man wc . wc -l告诉wc按照wc联机帮助页按行计数,以查看联机帮助页类型man wc

See the Linux Shell Scripting Tutorial A Beginner's handbook and the Advanced Bash-Scripting Guide for further references. 有关更多参考,请参见《 Linux Shell脚本教程初学者手册》和《 高级Bash脚本指南》

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM