此脚本是无意中在网上看到,觉得不错就拿来了。牛人们给做个脚本的解释,谢了!
#!/bin/bash
redir ()
{       
        tab=$tab$singletab
        line=${tab%"$singletab"}"|-------"
       
        local count=$#
        for file in "$@"; do
                thisfile=${thisfile:-$PWD}/$file                
                if [ -d "$thisfile" ]; then                     
                        if [ $count -eq 1 ]; then
                                echo -e $line$file/
                                #echo -e "end!"
                                tab=${tab%"$singletab"}"\t"
                                redir $(ls $thisfile)
                        else
                                echo -e $line$file/
                                #echo -e "this is directory!"
                                redir $(ls $thisfile)
                        fi         
                else
                        echo -e $line$file
                        #echo -e  "this is a file,you can do anything you want!"/
                fi
                thisfile=${thisfile%/*}
                let count=count-1      
        done
        tab=${tab%"\t"}
        tab=${tab%"|"}
        line=${tab%"$singletab"}"|-------"
}
singletab="|\t"
userinput="$@"
if ls $userinput; then
        for file in ${userinput:-.}; do
                echo $file
                echo '|'
                if [ -d "$file" ]; then
                        cd $file
                        redir $(ls)
                        cd ..
                fi
        done
else
        echo "$userinput is wrong"
fi