From 35fcf5cd9fbb2cd8ae4f62d483cf76a03f5a98a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A9lix=20Pi=C3=A9dallu?= Date: Mon, 15 Feb 2021 11:37:15 +0100 Subject: [PATCH] Add shebang to dead_links. Proper loop on command stdout. --- tests/dead_links.sh | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) mode change 100644 => 100755 tests/dead_links.sh diff --git a/tests/dead_links.sh b/tests/dead_links.sh old mode 100644 new mode 100755 index 08bf59b8..3624f13f --- a/tests/dead_links.sh +++ b/tests/dead_links.sh @@ -1,3 +1,6 @@ +#!/usr/bin/env bash +set -Eeuo pipefail + returncode=0 # Parse default routes @@ -7,11 +10,10 @@ grep -roh "^ *default: .*" ./pages | awk '{print $2}' | tr -d "'" | sort | uniq grep -rh "^---$" ./pages -B 50 | grep "^ *\- '/" | awk '{print $2}' | tr -d "'" | sort | uniq >> .known_pages # Find all markdown links and generate a list of filename.md:N:linktarget (with N the line number) -for LINK in $(grep -nr -o -E "\]\(\/?(\w|-)+\)" ./pages) -do - PAGE=$(echo $LINK | awk -F: '{print $3}' | tr -d ']()/') - grep -qw "$PAGE" ./.known_pages || { echo $LINK; returncode=1; } -done +while IFS= read -r LINK; do + PAGE=$(echo "$LINK" | awk -F: '{print $3}' | tr -d ']()/') + grep -qw "$PAGE" ./.known_pages || { echo "$LINK"; returncode=1; } +done < <(grep -nr -o -E "\]\(\/?(\w|-)+\)" ./pages) exit $returncode