| 1 | #!/bin/bashscip-shell filesystem . . `/bin/bash`. |
| 2 | # tree.sh |
| 3 | |
| 4 | # Written by Rick Boivie. |
| 5 | # Used with permission. |
| 6 | # This is a revised and simplified version of a script |
| 7 | #+ by Jordi Sanfeliu (the original author), and patched by Ian Kjos. |
| 8 | # This script replaces the earlier version used in |
| 9 | #+ previous releases of the Advanced Bash Scripting Guide. |
| 10 | # Copyright (c) 2002, by Jordi Sanfeliu, Rick Boivie, and Ian Kjos. |
| 11 | |
| 12 | # ==> Comments added by the author of this document. |
| 13 | |
| 14 | |
| 15 | searchscip-shell shell abs-guide 10-4 search(). () { |
| 16 | for dir in `echoscip-shell system . . echo. *` |
| 17 | # ==> `echo *` lists all the files in current working directory, |
| 18 | #+ ==> without line breaks. |
| 19 | # ==> Similar effect to for dir in * |
| 20 | # ==> but "dir in `echo *`" will not handle filenames with blanks. |
| 21 | do |
| 22 | if [scip-shell system . . `[`. -d "$dir" ] ; then # ==> If it is a directory (-d)... |
| 23 | zz=0 # ==> Temp variable, keeping track of |
| 24 | # directory level. |
| 25 | while [scip-shell system . . `[`. $zz != $1 ] # Keep track of inner nested loop. |
| 26 | do |
| 27 | echoscip-shell system . . echo. -n "| " # ==> Display vertical connector symbol, |
| 28 | # ==> with 2 spaces & no line feed |
| 29 | # in order to indent. |
| 30 | zz=`exprscip-shell system . . expr. $zz + 1` # ==> Increment zz. |
| 31 | done |
| 32 | |
| 33 | if [scip-shell system . . `[`. -L "$dir" ] ; then # ==> If directory is a symbolic link... |
| 34 | echoscip-shell system . . echo. "+---$dir" `lsscip-shell system . . ls. -l $dir | sedscip-shell system . . sed. 's/^.*'$dir' //'` |
| 35 | # ==> Display horiz. connector and list directory name, but... |
| 36 | # ==> delete date/time part of long listing. |
| 37 | else |
| 38 | echoscip-shell system . . echo. "+---$dir" # ==> Display horizontal connector symbol... |
| 39 | # ==> and print directory name. |
| 40 | numdirs=`exprscip-shell system . . expr. $numdirs + 1` # ==> Increment directory count. |
| 41 | if cd "$dir" ; then # ==> If can move to subdirectory... |
| 42 | searchscip-shell shell abs-guide 10-4 search(). `exprscip-shell system . . expr. $1 + 1` # with recursion ;-) |
| 43 | # ==> Function calls itself. |
| 44 | cd .. |
| 45 | fi |
| 46 | fi |
| 47 | fi |
| 48 | done |
| 49 | } |
| 50 | |
| 51 | if [scip-shell system . . `[`. $# != 0 ] ; then |
| 52 | cd $1 # Move to indicated directory. |
| 53 | #else # stay in current directory |
| 54 | fi |
| 55 | |
| 56 | echoscip-shell system . . echo. "Initial directory = `pwdscip-shell system . . pwd.`" |
| 57 | numdirs=0 |
| 58 | |
| 59 | searchscip-shell shell abs-guide 10-4 search(). 0 |
| 60 | echoscip-shell system . . echo. "Total directories = $numdirs" |
| 61 | |
| 62 | exit 0 |