
次の機能がありますが、5、6などがあると重複して拡張できません。
append_footnote(){
file=$1
if [ "$#" -ge 2 ];then
depth=$2
if [ $depth -eq 1 ];then
echo '<span style="float: footnote;"><a href="../index.html#toc">Go to TOC</a></span>' >> "$file"
elif [ $depth -eq 2 ];then
echo '<span style="float: footnote;"><a href="../../index.html#toc">Go to TOC</a></span>' >> "$file"
elif [ $depth -eq 3 ];then
echo '<span style="float: footnote;"><a href="../../../index.html#toc">Go to TOC</a></span>' >> "$file"
elif [ $depth -eq 4 ];then
echo '<span style="float: footnote;"><a href="../../../../index.html#toc">Go to TOC</a></span>' >> "$file"
fi
else
echo '<span style="float: footnote;"><a href="./index.html#toc">Go to TOC</a></span>' >> "$file"
fi
}
依存argの前に追加されました../
。どうすればもっと良くすることができますか?index.html#toc
$2
答え1
私はこれについて考えた。うまくいきますが、より良い解決策があれば教えてください。
repeat(){
END=$2
for i in $(eval echo "{1..$END}")
do
echo -n "$1"
done
}
append_footnote(){
file=$1
if [ "$#" -ge 2 ];then
depth=$2
path_str=$(repeat '../' $depth)
if [ $depth -gt 1 ];then
echo "<span style='float: footnote;'><a href=\"${path_str}index.html#toc\">Go to TOC</a></span>" >> "$file"
fi
else
echo '<span style="float: footnote;"><a href="./index.html#toc">Go to TOC</a></span>' >> "$file"
fi
}