zoukankan      html  css  js  c++  java
  • shell script

    1:递归树形展示目录

     1 ShowTab()
     2 {
     3     whitespace=""
     4     if [ $# -gt 0 ] && [ $1 -gt 0 ]; then
     5         for index in $(seq 1 $1)
     6         do
     7             whitespace="${whitespace}    "
     8         done
     9     fi
    10     echo "${whitespace}"
    11 }
    12 
    13 ShowDir()
    14 {
    15     #if [ $# == 0 ]; then
    16     #    echo "no argument,exit!"
    17     #elif [ ! -e $1 ]; then
    18     #    echo "filepath $1 is invalid"
    19     if [ -d $1 ]; then
    20         echo "$(ShowTab $2)$1"
    21         argLs=$(ls $1)
    22         for filename in ${argLs}
    23         do
    24             ShowDir $1/${filename} $(($2+1))
    25         done
    26     elif [ -f $1 ]; then
    27         echo "$(ShowTab $2)$1"
    28     fi
    29 }
    30 
    31 paramOne=""
    32 if [ $# == 0 ] ; then
    33     paramOne=$(pwd)
    34 else
    35     paramOne=$1
    36 fi
    37 
    38 if [ ! -e ${paramOne} ]; then
    39     echo "arg1: ${paramOne} is not exist"
    40     exit 0
    41 fi
    42 
    43 ShowDir ${paramOne} 0

    效果图:  

  • 相关阅读:
    React-使用combineReducers完成对数据对拆分管理
    Linux
    Linux
    linux
    linux
    Linux
    Linux
    Linux
    Linux
    Linux 系统基础优化和常用命令
  • 原文地址:https://www.cnblogs.com/hgwang/p/10350539.html
Copyright © 2011-2022 走看看