The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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 -->
  #1 (permalink)  
Old 03-12-2009
nuvpal nuvpal is offline
Registered User
  
 

Join Date: Mar 2009
Posts: 7
Function Recursion Shift Problem

Hi, I'm trying to create a script that will display the contents of the users directories, but i'm confused about how to incorporate the shift properly.

The problem I'm getting with my script is that it goes throught the first couple of directories but then returns an error as it loses the first directory when continuing the search to other directories (I hope that makes sense?!)
EDIT: I apologise, that was the old problem, now the problem is the path to be searched adds the wrong directories so it looks in paths that do not exist

Here's my code, any help would be greatly appreciated.

Code:
direc=~
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
 
        done
}
printList $list
EDIT2: I have also tried suppressing the error returned by the ls to dev null by editing the line inside the function:
Code:
                list=$(ls -l $direc/$1 | egrep '^d' | cut -d" " -f8 2>/dev/null)
and also
Code:
                list=$(ls -l $direc/$1 | egrep '^d' | cut -d" " -f8) 2>/dev/null
but niether work, both return the same output, in other words they are still not suppressesing the standard error.

Last edited by nuvpal; 03-12-2009 at 06:22 AM..