Quote:
Originally Posted by radoulov
What's wrong with:
... 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