Linux下统计txt文件的行数并存储为变量

有node.txt,其中的内容为:

node.txt:

22

43

64

统计node.txt中内容的行数,并将行数存储为变量nodenum,可使用如下命令:

nodenum=$(cat node.txt | wc -l) #注意这里是英文字母l,不是数字1

调用变量nodenum时,使用$nodenum即可。

猜你喜欢

转载自blog.csdn.net/qq_36480087/article/details/86302511