Anyway, here is a working recursive function:
Code:
function _recurselink {
mkdir -p "${2// /.}"
for item in "$1"/*
do
if [[ -f "$item" ]]
then
ln -s "$item" "${2// /.}"
fi
if [[ -d "$item" ]]
then
_recurselink "$item" "$2/${item##*/}"
fi
done
}
It is independent from the actual path (notice it does not define source or target) and you have to call it with two arguments, the source directory (absolute path) and the target directory, exactly the same as the suggested
cp command:
Code:
_recurselink /home/complete /tempcomplete
Also notice that using the
-p option of
mkdir makes the test for the existence of the directory not necessary.