| Line |  | 
|---|
| 1 | #!/bin/bash | 
|---|
| 2 | # | 
|---|
| 3 | # Name: dirtree | 
|---|
| 4 | # Programmer: | 
|---|
| 5 | #            Hemant T. Shah | 
|---|
| 6 | #            Life Insurance Data Processing | 
|---|
| 7 | #            July 12 1994 | 
|---|
| 8 | # | 
|---|
| 9 | # Description: | 
|---|
| 10 | #  Print directory tree structure as follows: | 
|---|
| 11 | #   |___Mail | 
|---|
| 12 | #     |___scheduler | 
|---|
| 13 | #     |___cics_scripts | 
|---|
| 14 | #     |___tar_msdos | 
|---|
| 15 | #     |___awk | 
|---|
| 16 | #     |___attributes | 
|---|
| 17 | #   |___tmp | 
|---|
| 18 | #   |___News | 
|---|
| 19 | #     |___dosscsi | 
|---|
| 20 | #     |___FAQ_xterminal | 
|---|
| 21 | #     |___shell_history.Z | 
|---|
| 22 | #     |___FAQ_AIX | 
|---|
| 23 | #     |___aix_ftp_site | 
|---|
| 24 | #     |___hp_software | 
|---|
| 25 | #   |___dnload | 
|---|
| 26 | #     |___telnet.h | 
|---|
| 27 | #     |___msdos | 
|---|
| 28 | #     |___tnetd.tar.Z | 
|---|
| 29 | #     |___aix | 
|---|
| 30 | #     |___hp | 
|---|
| 31 | #   |___xkey.c | 
|---|
| 32 | # | 
|---|
| 33 | # Conversion to bash v2 syntax done by Chet Ramey | 
|---|
| 34 | #       - removed command substitutions calling `basename' | 
|---|
| 35 | # | 
|---|
| 36 |  | 
|---|
| 37 | ProgramName=${0##*/} | 
|---|
| 38 | Path="." | 
|---|
| 39 | ShowAll=1 | 
|---|
| 40 | ShowDir=0 | 
|---|
| 41 |  | 
|---|
| 42 |  | 
|---|
| 43 | ExpandDirectory() | 
|---|
| 44 | { | 
|---|
| 45 | local object   # Local variable | 
|---|
| 46 |  | 
|---|
| 47 | cd "$1" | 
|---|
| 48 |  | 
|---|
| 49 | for object in $PWD/.??* $PWD/* | 
|---|
| 50 | do | 
|---|
| 51 | if [ -d $object ];  # It is a directory | 
|---|
| 52 | then | 
|---|
| 53 | echo "${indent}|___${object##*/}/" | 
|---|
| 54 | indent="${indent}!   "   # Add to indentation | 
|---|
| 55 | if [ -x $object ]; | 
|---|
| 56 | then | 
|---|
| 57 | ExpandDirectory $object | 
|---|
| 58 | fi | 
|---|
| 59 | indent=${indent%????}    # Remove from indentation | 
|---|
| 60 | elif [ -e $object ]; then | 
|---|
| 61 | if (( ShowAll == 1 )); | 
|---|
| 62 | then | 
|---|
| 63 | echo "${indent}|___${object##*/}" | 
|---|
| 64 | fi | 
|---|
| 65 | fi | 
|---|
| 66 | done | 
|---|
| 67 |  | 
|---|
| 68 | } | 
|---|
| 69 |  | 
|---|
| 70 | usage() | 
|---|
| 71 | { | 
|---|
| 72 | echo -e "Usage: $ProgramName [-h] [-f] [-d] [path] " | 
|---|
| 73 | echo -e "\t-h       ... display this help message." | 
|---|
| 74 | echo -e "\t-f path  ... shows all files and directories below path (default)." | 
|---|
| 75 | echo -e "\t-d path  ... shows all directories only below path." | 
|---|
| 76 | } | 
|---|
| 77 |  | 
|---|
| 78 | while getopts "fd" opt | 
|---|
| 79 | do | 
|---|
| 80 | case $opt in | 
|---|
| 81 | f) ShowAll=1 ;; | 
|---|
| 82 | #d) ShowDir=1 ;; | 
|---|
| 83 | d) ShowAll=0 ;; | 
|---|
| 84 | *) usage ; exit 2;; | 
|---|
| 85 | esac | 
|---|
| 86 | done | 
|---|
| 87 |  | 
|---|
| 88 | shift $(( $OPTIND - 1 )) | 
|---|
| 89 |  | 
|---|
| 90 | Path=${1:-.} | 
|---|
| 91 |  | 
|---|
| 92 | if [ ! -d "$Path" ]; then | 
|---|
| 93 | echo "$0: error: specified path is not a directory." >&2 | 
|---|
| 94 | exit 1 | 
|---|
| 95 | fi | 
|---|
| 96 |  | 
|---|
| 97 |  | 
|---|
| 98 |  | 
|---|
| 99 | echo "!$Path/" | 
|---|
| 100 | ExpandDirectory $Path | 
|---|
       
      
  Note:
 See   
TracBrowser
 for help on using the repository browser.