美文网首页
shell 读取文件并且输出

shell 读取文件并且输出

作者: autisticBoy | 来源:发表于2019-03-19 13:14 被阅读0次

第一步:写一个文件或者下载一个

第二步:编写shell脚本

#!bin/ bash    # 告诉系统用bash 执行
count=0 #变量与=之间不能有空格
for line in $  `cat filename` # 逐行读取文件
do          # 循环 与done 一起
  echo $line  #输出 $加变量表示变量的值
  count=`expr $count + 1` # 加号与前后两个变量必须有空格 ,count自增
done
echo $count

运行

chmod +x ./test.sh #使脚本具有执行权限
./test

image.png

相关文章

网友评论

      本文标题:shell 读取文件并且输出

      本文链接:https://www.haomeiwen.com/subject/bdegmqtx.html