KGRKJGETMRETU895U-589TY5MIGM5JGB5SDFESFREWTGR54TY
Server : Apache/2.2.17 (Unix) mod_ssl/2.2.17 OpenSSL/0.9.8e-fips-rhel5 DAV/2 PHP/5.2.17
System : Linux localhost 2.6.18-419.el5 #1 SMP Fri Feb 24 22:47:42 UTC 2017 x86_64
User : nobody ( 99)
PHP Version : 5.2.17
Disable Function : NONE
Directory :  /usr/share/doc/bash-3.2/functions/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : //usr/share/doc/bash-3.2/functions/recurse
#!/bin/bash

#From: kaz@ashi.footprints.net (Kaz Kylheku)
#Newsgroups: comp.os.linux.misc
#Subject: Re: bash question: subdirectories
#Message-ID: <slrn8a0gu9.v5n.kaz@ashi.FootPrints.net>
#Date: Tue, 08 Feb 2000 16:24:35 GMT

#Actually it can be made to. That is to say, it is possible to code a recursive
#descender function in the bash language. Here is an example. 
#
#What is nice about this is that you can embed the function into your shell
#script. The function changes the current working directory as it descends.
#So it can handle arbitrarily deep paths. Whereas paths generated by the
#find command can cause a problem when they get too long; the kernel has a
#hard limit on the length of the string passed to the open() and other
#system calls. 

#There are races; what if the directory tree is blown away during the traversal?
#The function won't be able to crawl back up using the .. link and will just
#bail.

# Recursive Directory Traverser
# Author: Kaz Kylheku
# Date: Feb 27, 1999
# Copyright 1999

# Function parameter usage:
# $1 directory to search
# $2 pattern to search for
# $3 command to execute
# $4 secret argument for passing down path

function recurse
{
    local file
    local path

    if [ "$4" = "" ] ; then
        path="${1%/}/"
    else
        path="$4$1/"
    fi

    if cd "$1" ; then
        for file in $2; do
            if [ -f "$file" ] || [ -d "$file" ]; then
                eval "$3"
            fi
        done
        for file in .* * ; do
            if [ "$file" = "." ] || [ "$file" = ".." ] ; then
                continue
            fi
            if [ -d "$file" ] && [ ! -L "$file" ]; then
                recurse "$file" "$2" "$3" "$path"
            fi
        done
        cd ..
    fi
}

recurse "$1" "$2" 'echo "$path$file"'

Anon7 - 2021