qfedu-linux-advanced-level/day1/homework/h3.sh

13 lines
435 B
Bash
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/bash
# 编写一个Shell脚本接受一个文件名作为参数并统计该文件中的行数、单词数和字符数
# 【提示】wc 统计命令
if [ -e $1 ] && [ -f $1 ]; then
echo "文件名:$1"
echo "行数:`wc -l $1 | awk '{print $1}'`"
echo "单词数:`wc -w $1 | awk '{print $1}'`"
echo "字符数:`wc -c $1 | awk '{print $1}'`"
else
echo "文件不存在或者不是一个文件"
fi