Recursively hard linking files -- bonehead question

I used to program ksh a while back, but I've been off in Oracle/Windows land (for clients -- not by choice) for so long that I can't remember what should be an easy thing. Here's the scenario:

1)Find all files and directories beneath some directory point (A).
2)If directory, make the subdirectory at some different directory point (B)
3)If file, link (not symbolic) the file in the correct subdirectory under point B.

For a more concrete example, here's a scenario.

Point A: /usr/test
Point B: /var/test

File structures:
/usr/test
/usr/test/oracle
/usr/test/oracle/script 1
/usr/test/oracle/script 2
/usr/test/db2
/usr/test/db2/script 1
/usr/test/db2/script 2

I'm trying to write a script that will result in the following output (and/or actually do the work instead of writing an output script, but I can live with creating a secondary script):

mkdir /var/test/oracle
ln /usr/test/oracle/"script 1" /var/test/oracle/"script 1"
ln /usr/test/oracle/"script 2" /var/test/oracle/"script 2"
mkdir /var/test/db2
ln /usr/test/db2/"script 1" /var/test/db2/"script 1"
ln /usr/test/db2/"script 2" /var/test/db2/"script 2"

Here's the pseudo code for what I've been working on so far:

#!/bin/bash

#declare variables
cnt=0 #array counter
# &1 == Source Directory
# &2 == Target Directory
source_len=awk '{ print length }'

# Find out what the subdirectories are
full_list=find $1 -print 2>/dev/null

## Populate the subdirectories into an array
## Trim the root from the subdirectories into a second array
subdir = full_list| cut -c source_len-

# Loop through, creating them one at a time.
if [-d full_list]
then
# make the new directory
echo "mkdir $target/$subdir"
elif [-f source]
then
# link the file
echo "ln $full_list $target/$subdir"
fi

Someone suggested to me mounting /usr/test to /var/test, but that doesn't completely satisfy the necessary requirements (and would result in a few thousand mount points being scattered through the environment -- not a pretty picture)...

if this was PL/SQL, it would have taken me about 15 seconds to write, but I'm rusty on bash scripting. Any thoughts?

--CS

no error checking but first thoughts:

oldifs=$IFS
IFS='
'
find /home/chris/tmp/usr/test |
while read f
do
    dest=$(echo $f | sed 's/usr/var/')
    [ -d "$f" ] && mkdir -p "$dest" || ln "$f" "$dest"
done
IFS=$oldifs

this produced:

find /home/chris/tmp/usr
/home/chris/tmp/usr
/home/chris/tmp/usr/test
/home/chris/tmp/usr/test/oracle
/home/chris/tmp/usr/test/oracle/script 1
/home/chris/tmp/usr/test/oracle/script 2
/home/chris/tmp/usr/test/db2
/home/chris/tmp/usr/test/db2/script 1
/home/chris/tmp/usr/test/db2/script 2

find /home/chris/tmp/var
/home/chris/tmp/var

bash linker.sh
find /home/chris/tmp/var
/home/chris/tmp/var
/home/chris/tmp/var/test
/home/chris/tmp/var/test/oracle
/home/chris/tmp/var/test/oracle/script 1
/home/chris/tmp/var/test/oracle/script 2
/home/chris/tmp/var/test/db2
/home/chris/tmp/var/test/db2/script 1
/home/chris/tmp/var/test/db2/script 2

and if you run ls -lRi on both dirs you should see that the files are linked, not copied.

Unfortunately, the /usr and /var are just examples. I was hoping to parameterize the two directories to support changing it on the fly at runtime.

--CS

srcdir=/some/dir
targetdir=/some/other/dir
  {{snip}}
find $srcdir |
  {{snip}}
    dest=$(echo $f | sed "s#$srcdir#$targetdir#")
  {{snip}}

Okay, so to make source directory and target directory command line parameters, it would be something like:

srcdir=$1
targetdir=$2

Right?

certainly would, yes.

Okay, I finally got a break in work that pays to try this out. Here's the script:

srcdir=$1
targetdir=$2

oldifs=$IFS
IFS='
'
find $srcdir |
while read f
do
    dest=$(echo $f | sed 's#$srcdir#$targetdir#g')
    echo $srcdir
    echo $targetdir
    echo $dest
    echo $f
    echo $f |sed 's/\/library\/\data\/Total List/$targetdir/g'
#    [ -d "$f" ] && mkdir -p "$dest" || ln "$f" "$dest"
done
IFS=$oldifs

And the results (just to provide a sample) are:

Thoughts/Suggestions?

Use " quotes around your sed script instead of ', otherwise variables' values are not substituted into the string.