[sf-lug] bash: identifying directories

Clyde Jones slash5toaster at gmail.com
Tue Jun 3 11:24:57 PDT 2008


On Tue, Jun 3, 2008 at 11:10 AM, Matt Price <matt.price at utoronto.ca> wrote:
> another little scripting question:
>
> i'd like this tiny script i'm writing to scan the current directory,
> identify the subdirectories, and then do something in each of them.  so
> in pseudocode:
>
> [find dirs]
>
> for DIR in $dirs ; do
>        cd $DIR
>        [do some stuff]
>        cd ..
> done
>
> is this trivial to do?  20 minutes with the abs-guide hasn't given me
> the answer yet...
>
> thanks much!
>
> matt

#!/bin/sh

#variables
# this set the delimiter to be a carriage return ONLY instead of space
plus carriage return -
#so we can handle items with a space in  the name
oldIFS=$IFS
IFS="
"
SUBDIR=$(find . -maxdepth 1 -type d)

for DIRS in $SUBDIR
 do
    # your thing
    echo "Thrashing $DIRS in $SUBDIR"
 done

#cleanup!!
IFS=$oldIFS



Not so bad

 Dirlist

-- 
We are what we think. All that we are arises with our thoughts. With
our thoughts, we make the world.
-Buddha




More information about the sf-lug mailing list