最新是行为的" WC"命令? [英] Whats is the behaviour of the "wc" command?

查看:208
本文介绍了最新是行为的" WC"命令?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如:

myCleanVar=$( wc -l < myFile )
myDirtVar=$( wc -l myFile )

echo $myCleanVar
9

echo $myDirtVar
9 myFile

为什么在myCleanVar我从WC命令,并在myDirtVar一个整数的价值我得到类似为:9 file.txt的?我引用整数,因为知道,在默认情况下的Bash shell都被作为一个字符串处理,但无法理解第一和第二的前pression的行为差异。什么是重定向的特定效应&下;在这种情况下?

why in "myCleanVar" I get an "integer" value from the "wc" command and in "myDirtVar" I get something like as: "9 file.txt"? I quoted "integer" because in know that in Bash shell by default all is treated as a string, but can't understand the differences of the behaviour of first and second expression. What is the particular effect of the redirection "<" in this case?

推荐答案

厕所将默认列表文件的名称,让您可以使用它在多个文件(并对所有他们的结果)。如果没有指定文件名,标准输入,这通常是在控制台输入,被使用,并且没有印刷文件名。在&LT; 需要指定一个输入重定向,即读取指定的文件,而不是使用用户输入的输入

wc will list by default the name of file allowing you to use it on more than one file (and have result for all of them). If no filename is specified, the "standard input", which is usually the console input, is used, and no file name is printed. The < is needed to specify an "input redirection", that is read the input from given file instead of using user input.

一起把所有这些信息,你会得到的WC 的原因的行为在你的榜样

Put all this information together and you get the reason of wc's behavior in your example

提问时间:这将是猫文件的输出|厕所-l

这篇关于最新是行为的&QUOT; WC&QUOT;命令?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆