#!/bin/bash File=`ls` i=0 for Var in $File do if [ -d $Var ] then echo "$Var is a directory" i=`expr $i + 1` fi done echo "total directory is $i" 测试结果