Skip to content

Commit 2ed6d5d

Browse files
committed
Fix shellcheck warnings in fix-haddock-links.sh
Replace sed call with bash regex parameter expansion (SC2001) and annotate the xargs sh -c command with a shellcheck disable directive for SC2016 (the single quotes are intentional — the expansions must be evaluated by the inner sh -c, not the outer shell).
1 parent 77faa54 commit 2ed6d5d

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

scripts/fix-haddock-links.sh

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,12 @@ while IFS= read -r target; do
147147
# Already exists?
148148
[[ -e "$WEBSITE_DIR/$target" ]] && continue
149149
# Strip version+hash: "base-4.20.2.0-f074" -> "base"
150-
# Pattern: strip everything from the first "-DIGIT" onward
151-
short_name=$(echo "$target" | sed 's/-[0-9][0-9]*\..*//')
150+
# Pattern: strip everything from the first "-DIGIT.DIGIT" onward
151+
if [[ "$target" =~ ^(.+)-[0-9]+\.[0-9] ]]; then
152+
short_name="${BASH_REMATCH[1]}"
153+
else
154+
short_name="$target"
155+
fi
152156
if [[ -v "SHORT_DIRS[$short_name]" ]]; then
153157
ln -s "$short_name" "$WEBSITE_DIR/$target"
154158
symlink_count=$((symlink_count + 1))
@@ -301,6 +305,7 @@ DEAD_URLS_FILE=$(mktemp)
301305
trap 'rm -f "$CHAP_PKGS_FILE" "$URLS_FILE" "$DEAD_URLS_FILE"' EXIT
302306

303307
if [[ $url_count -gt 0 ]]; then
308+
# shellcheck disable=SC2016 # single quotes intentional: expansions evaluated by inner sh -c
304309
xargs -P 16 -I{} sh -c \
305310
'code=$(curl -sI -o /dev/null -w "%{http_code}" --connect-timeout 5 --max-time 10 "{}"); if [ "$code" != "200" ] && [ "$code" != "301" ] && [ "$code" != "302" ]; then echo "{}"; fi' \
306311
< "$URLS_FILE" > "$DEAD_URLS_FILE" 2>/dev/null

0 commit comments

Comments
 (0)