script: allow to run script from any location

This commit is contained in:
Morgan 2018-09-12 03:38:54 +02:00
parent aa23bf01bc
commit f3c40fbeb2

View File

@ -1,12 +1,14 @@
#!/bin/bash #/usr/bin/env bash
BASEDIR=$(dirname "$0")
current=$(date "+%Y") current=$(date "+%Y")
for ((year=1900; year<=current; year=year+1)) for ((year=1900; year<=current; year=year+1))
do 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 do
echo "$line" 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") 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" ) 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
done done