Recursive calls

Discussion in 'HOWTO-Related Questions' started by dallnsn, Aug 25, 2008.

  1. dallnsn

    dallnsn New Member

    I am trying to display information from my current directory into a 5 column format, but I am stuck on where to start. If anyone could offer some assistance it would be greatly appreciated. Someone has mentioned a recursive call to the shell script may make the task a little easier.


    Thanks
     
  2. topdog

    topdog Active Member

    What do u actually want to achieve as you are not clear on what you want.
     
  3. dallnsn

    dallnsn New Member

    Recursive calls.

    Hi topdog,

    Yes, it must be frustrating trying to work out what people are saying in their posts, just like it is for me a very novice linux user that has to design scripts in an obviously abstract programming language for such a novice like myself.

    this script is supposed to display the present working directory and lists it contents in 5-column format on the screen, the program has to accept the starting directory as a positional parameter and descend through the directories and subdirectories and list their contents in the above said "5 column format."

    This is what I have tried, but has not worked.

    #!/bin/bash
    # FILE: PartC


    chmod 770 PartC
    set -x

    wcfiles()
    {
    local BASEDIR=$1 # Set the local base directory
    local LOCALDIR=`dallnsn` # Where are we?
    cd $BASEDIR # Go to this directory (down)
    local filelist=`ls -r` # Get the files in this directory
    for file in $filelist
    do
    if [ -d $file ] # If we are a directory, recurs
    then
    # we are a directory
    wcfiles "$BASEDIR/$file"
    else
    fc=`wc -w < $file` # do word count and echo info
    echo "$BASEDIR/$file $fc words"
    fi
    done
    cd $LOCALDIR # Go back up to the calling directory
    }

    if [ $1 ] # Default to . if no parms
    then
    wcfile $1
    else
    wcfile "."
    fi


    Well that's about it, I can't say anymore than that.

    Any help would be greatly appreciated.
     
  4. topdog

    topdog Active Member

    Why don't you use find to traverse the directory instead of doing recursive calls.
     

Share This Page