shell 脚本统计当前目录下普通文件个数
#!/bin/bash
#The shell function used to count how many files in the current dirctory
count=0
for files in *
do
if [ -f "$files" ]
then
count=`expr $count + 1`
fi
done
echo "There are $count files in `pwd`"
[root@localhost sourcetemp]# ./filecount
There are 75 files in /mnt/hgfs/share/sourcetemp
注意问题:
1.for循环后跟do 配合done结束,结束for循环,需注意done的位置。
2.=赋值左右没有空格。
3.· ·是tab键上的符号,而不是' '。