The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
command terminated abnormally tkbharani UNIX for Advanced & Expert Users 0 08-02-2007 04:36 AM
how to differentiate system call from library call muru UNIX for Advanced & Expert Users 2 07-20-2007 12:20 AM
start time of a terminated process k_chaaya UNIX for Advanced & Expert Users 2 09-04-2006 01:57 AM
Process got terminated automatically Elango AIX 4 01-02-2006 11:37 PM
How to supress a "Killed" message when a process is terminated? kenwolff UNIX for Advanced & Expert Users 2 03-22-2004 11:17 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 10-17-2006
tipsy tipsy is offline
Registered User
  
 

Join Date: Jun 2006
Posts: 35
Thumbs up Recursive method call getting terminated ???

Hello people,

Need help !!! What am I doing wrong here ?

I am writing a function to recursively list the files under a folder and it's sub-folders. Problem is once it list the files under the innermost folder, it terminates. What do I need to do so that it returns and list files under the other folders under the topmost folder. Below please find the method declaration:

############################################
listfiles()
############################################
{
dir=$1

echo "Listing files under folder $dir"
files=`ls -1 $dir`

for file in `echo $files`
do
if [ -d $dir/$file ]; then
#recursive call
listfiles $dir/$file
fi

echo $dir/$file
done
}

Regards,
T.
  #2 (permalink)  
Old 10-17-2006
tipsy tipsy is offline
Registered User
  
 

Join Date: Jun 2006
Posts: 35
Is it because the value of the variable "files" is getting overwritten in each recursive call? Do I have to make the variable name dynamic instead of "files" ?

Regards,
T.
  #3 (permalink)  
Old 10-17-2006
vgersh99's Avatar
vgersh99 vgersh99 is online now Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,131
wouldn't it be easier to do 'find . -type f' ?

Last edited by vgersh99; 10-18-2006 at 11:47 AM..
  #4 (permalink)  
Old 10-18-2006
tipsy tipsy is offline
Registered User
  
 

Join Date: Jun 2006
Posts: 35
Smile

Thanks vgersh99.
I should have posted this query much earlier instead of breaking me head :-)

Regards,
T.
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 11:15 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0