I wrote a symlink script for someone on another team to run in a directory I don't have access to, and it seemed to have caused something unexpected.
destination_path=/path/to/dest/ source_path=/path/to/src for dir in first second do # replace existing symlink for subdir in {1000..1020} do ln -sf $source_path/$dir/$subdir $destination_path/$dir/$subdir done done Before the script was run path/to/dest/$dir contains symlinks 1000, 1001, ..., 1020 that's linked to a different set of directories. My script is intended to replace those symlinks with symlinks to /path/to/src/$dir/$subdir, but instead of doing that, it seems to have created the symlinks within the existing symlink.
So for example, /path/to/dest/$dir/1000 used to be a symlink, and after running my script /path/to/dest/$dir/1000 is still points to the same place but within /path/to/dest/$dir/1000, there is a sym link 1000 that points to $source_path/$dir/$subdir/1000.
This shouldn't have occurred with my script right? I tried to reproduce this locally with a mocked destination directory structure and I couldn't reproduce this issue.
Edit: upon further research, it seems I should have used ln -sfn instead of just ln -sf? What is the easiest way to remedy this?