#!/bin/bash
clear
shopt -s failglob
source="${PWD%/*/*}"
workshop="$source/workshop/content/211820"
mods=$PWD/mods
mkdir -p "$mods" || exit
for pathname in "$workshop"/*/contents*.pak; do
name=${pathname#"$workshop"/}
name=${name%/*}-${name#*/}
ln -s "$PWD/$pathname" "$mods/$name"
done
I have a BASH script that scans the workshop
directory for all files named contents.pak
within the folders inside. The script then creates a symbolic link to the mods
directory with the name format: folder-contents.pak
. The script then repeats this process until there are no more files to create a symbolic link of.
The script itself is working fine, however, all the symbolic links that appear are broken.
The file and folder structure looks about like this:
.
├── common
│ └── Server
│ ├── linux
│ │ └── server_software
│ └── mods
├── server.acf
└── workshop
└── content
└── 211820
└── 1234
└── contents.pak
I have tried running ln -s
with sudo or using absolute paths but the outcome are still broken symbolic links. Is there anything I can do to fix this?
CodePudding user response:
ln -s "$PWD/$pathname" "$mods/$name"
What could I be doing wrong?
As $pathname
is already absolute, it's the prepending of $PWD/
which does harm; just drop that.