[CLUE-Tech] Just a little help?

David Willson DLWillson at TheGeek.NU
Wed Jan 14 20:35:06 MST 2004


I got the hard part done.  Or so it seems.  I have written a script that will
replace a 'source' directory's name in all the found directory-names with a
target directory's name.  Now, I want to test each line of output for
directory-ness, and record the source directory that doesn't have a matching target.

Help?  Pretty-please?

Script is quoted below.

----- Forwarded message from dlwillson at mailman.thegeek.nu -----

#!/bin/bash

#  ~this~ takes two directories as arguments
#  and verifies that all folders in the first exist as folders in the second.
#  Author: David L. Willson, (303) 299-8042, DLWillson at TheGeek.NU
#  Created: 2004 JAN

srce="/home/dlwillson/"
dest="/backup/dlwillson/"

# Validate directories
if [ ! -d $srce ]
  then echo $srce "is not a directory" ; exit 1
fi
if [ ! -d $dest ]
  then echo $dest "is not a directory" ; exit 1
fi

#  What I need to do next (escape the slashes):
#  $ echo "/home/dlwillson/.kde" | sed -e s/[/]/'\\\/'/g
#  \/home\/dlwillson\/.kde

sedCmnd="s/[/]/\\\\\\//g"
eSrce=`echo $srce | sed -e $sedCmnd`
eDest=`echo $dest | sed -e $sedCmnd`

# Echo variables back
echo '$srce='$srce
echo '$dest='$dest
echo '$eSrce='$eSrce
echo '$eDest='$eDest

sedCmnd="s/$eSrce/$eDest/"
echo '$sedCmnd='$sedCmnd

# [ -d `sed -e $sedCmnd` ] && echo "Destination exists" || echo "Destination
doesn't exist"

find $srce -type d | sed -e "$sedCmnd"

echo "Done."

----- End forwarded message -----


-------------------------------------------------
This mail sent through IMP: http://horde.org/imp/



More information about the clue-tech mailing list