操原作业(二) 编写一个shell脚本读取文件显示每一行并统计行数
作业要求如图代码:
#!/bin/bash
#读取、输出文本文件并统计行数
echo "Please enter a filename:"
count=0
read File
while read Line
do
echo $Line
count=$(($count+1))
done < $File
echo "THere are $count lines."
代码说明:
echo:打印
count=0:定义变量count用于计数,注意=左右不能有空格
read File:将读取的字符串赋值给File
read Line:按行读取文件,赋值给Line
while:循环
演示: