The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #3 (permalink)  
Old 03-12-2009
nuvpal nuvpal is offline
Registered User
  
 

Join Date: Mar 2009
Posts: 7
Quote:
Originally Posted by radoulov View Post
What's wrong with:

Code:
ls ~username
... or I'm missing something?

Could you post an example of the desired output?
I'm not quite sure what ls ~username would do, when I try it, it outputs the same as a normal ls command...

Basically what I want my script to do is display a visual representation of the specified directory and all its sub directories (like the tree command).

I have managed to supress the original ls error by adding the 2>/dev/null to the function call itself which seems to work ok now:
Code:
#!/bin/bash
direc=~
seperator=....
list=$(ls -l $direc | egrep '^d' | cut -d" " -f8)
function printList() {
        for line in $*
        do
                echo $line
                list=$(ls -l $direc/$1 | egrep '^d' | cut -d" " -f8 )
                direc=$direc/$1
                shift
                printList $list 2>/dev/null

        done
}
printList $list 2>/dev/null
But my script still does not work correctly, it will scan through the first directory found and display it along with all the subdirectories, but when it comes to loop back to the original directory and display the next directory it won't scan through and display the subdirectories of it. (I'm finding it quite hard to explain but I hope you can understand)

the output given will be something like: (where the . and number represent the directories and subdirectories)
direc1
direc1.1
direc1.1.1
direc1.1.2
direc1.2
direc1.2.1
direc2

and then it halts, where as i want it to display an output like:
direc1
direc1.1
direc1.1.1
direc1.1.2
direc1.2
direc1.2.1
direc2
direc2.1
direc2.1.1
direc2.2
direc2.2.1
direc3
direc3.1
direc3.1.1
direc3.2
direc4
...etc

Last edited by nuvpal; 03-12-2009 at 08:26 AM..