From f3c40fbeb22a59647173f8fa576643b791799be4 Mon Sep 17 00:00:00 2001 From: Morgan Date: Wed, 12 Sep 2018 03:38:54 +0200 Subject: [PATCH] script: allow to run script from any location --- fix_missing_dates.sh | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/fix_missing_dates.sh b/fix_missing_dates.sh index 0721829..1fa7ed8 100644 --- a/fix_missing_dates.sh +++ b/fix_missing_dates.sh @@ -1,12 +1,14 @@ -#!/bin/bash +#/usr/bin/env bash +BASEDIR=$(dirname "$0") + current=$(date "+%Y") for ((year=1900; year<=current; year=year+1)) do - grep "/$year/" README.md | grep -v "($year)" | grep -v " - (" | while read -r line + grep "/$year/" "$BASEDIR/README.md" | grep -v "($year)" | grep -v " - (" | while read -r line do echo "$line" replace=$(echo "$line" | sed "s/) - /) - ($year) /g" | sed -e "s#\*#\\\*#g" | sed -e "s#\[#\\\[#g" | sed -e "s#\]#\\\]#g" | sed -e "s#/#\\\/#g") orig=$(echo "$line" | sed -e "s#/#\\\/#g" | sed -e "s#\*#\\\*#g" | sed -e "s#\[#\\\[#g" | sed -e "s#\]#\\\]#g" ) - sed -i.bak "s;$orig;$replace;g" README.md + sed -i.bak "s;$orig;$replace;g" "$BASEDIR/README.md" done done