From owner-freebsd-questions@FreeBSD.ORG Fri Jan 8 10:23:11 2010 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 07E6B1065679 for ; Fri, 8 Jan 2010 10:23:11 +0000 (UTC) (envelope-from bth@higonnet.net) Received: from smtp4-g21.free.fr (smtp4-g21.free.fr [212.27.42.4]) by mx1.freebsd.org (Postfix) with ESMTP id 6CCB08FC0A for ; Fri, 8 Jan 2010 10:23:08 +0000 (UTC) Received: from smtp4-g21.free.fr (localhost [127.0.0.1]) by smtp4-g21.free.fr (Postfix) with ESMTP id B98924C8057 for ; Fri, 8 Jan 2010 11:23:05 +0100 (CET) Received: from freebsd.higonnet.net (higonnet.net [82.238.41.134]) by smtp4-g21.free.fr (Postfix) with ESMTP id CF0F54C80C2 for ; Fri, 8 Jan 2010 11:23:02 +0100 (CET) Received: from shopi.higonnet.net (shopi.higonnet.net [192.168.3.111]) by freebsd.higonnet.net (Postfix) with ESMTP id 1038DC7E4 for ; Fri, 8 Jan 2010 11:23:54 +0100 (CET) Message-ID: <4B4707A5.2000009@higonnet.net> Date: Fri, 08 Jan 2010 11:23:33 +0100 From: "Bernard T. Higonnet" User-Agent: Thunderbird 2.0.0.18 (X11/20081216) MIME-Version: 1.0 To: freebsd-questions@freebsd.org Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: Can't figure out recursion problem in bash/freebsd - reply/solution to all helpers X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 08 Jan 2010 10:23:11 -0000 Hello, There were two approaches offered to my problem 1) changing my script: it runs if the "cd .." is moved from the end of the script into the then clause of the if statement =============== #! /bin/sh echo Starting in `pwd` for hoo in *; do echo Found item $hoo if [ -d "$hoo" ]; then echo Pushing $hoo cd $hoo $0 cd .. else echo Processing file $hoo fi echo Going to next item done echo Finishing in `pwd` # cd .. was here in original script =============== I shall be bold: this strikes me as a bug in bash. Am I off my nut here? 2) use find instead for the traversing of the file hierarchy =============== find $PWD -type f -execdir processingscript {} \; =============== I have tried both methods and on a small sample (10,000 files going only 3 deep) and there were no meaningful differences in execution time. Thanks to all Bernard Higonnet