bash 遍历目录文件

 

#!/bin/bash
# 定义一个方法 它有一个参数代表目录
foreachd(){
        for file in $1
            do
                if [ -d $file ]
                then
                    echo $file"是目录" 
                    foreachd $file
                elif [ -f $file ]
                then
                    echo $file
                fi
            done
}

# 执行,如果有参数就遍历指定的目录,否则遍历当前目录
if [[ "x$1" == 'x' ]]
then
    foreachd "."
else
    foreachd "$1"
fi 

 

posted @ 2013-08-16 16:10  皁仩腄覺  阅读(756)  评论(0编辑  收藏  举报