Крик о помощи! Скрипт bash который меняет txt в html. Не запускается, помогите срочно!!
Скрипт который меняет txt в html. В скрипт добавляет параграфы, картинки и ссылки. Готовый скрипт не запускается, не могу найти ошибку.. Срочно прошу о помощь!
---------------------------------------------------------------- Файл v2.sh ----------------------------------------------------------------
#!/bin/bash
# there are 5 tags to be searched,
# <p> => beginning of the file till the end,
# </p><p> => on \n\n
# <b> on " *" and </b> on "* "
# {lll} into link with link as a test
# {aaa|bbb} into link with alternated text
usage="Usage: $0 -f outfile|- [<infile]"
outfile=""
if [ $# -ne 2 ]; then
echo "$usage"
exit 1
fi
if [ $# -eq 2 ]; then
while getopts ":f:h" optname
do
case "$optname" in
"h")
echo "$usage"
;;
"f")
if [[ "$optname" == "" ]]; then
echo "no output filename provided! Exit!"
exit 2
fi
outfile=$OPTARG
;;
*)
echo "Unknown error while processing options"
echo "$usage"
;;
esac
done
fi
url_re='(.*)(\{)(.*)(\})(.*)'
img_re='(.*)(\[)(.*)(\])(.*)'
italic_re='(.*)( _)(.*)(_ )(.*)'
bold_re='(.*)( \*)(.*)(\* )(.*)'
out=tmp
function subst {
echo $( cat $out | sed s/"$1"/"$2"/g ) > tmp2
mv tmp2 $out
}
# main loop for input
echo '<html><head></head><body><p>' > $out
#IFS=$'\n'
while read line # For as many lines as the input file has...
do
if [ "$line" == "" ]; then
echo "</p>\n<p>" >> $out
else
echo "$line" >> $out
fi
done
echo "</p></body></html>" >> $out
subst " _" " <i>"
subst "_ " "<\/i> "
subst " \*" " <b>"
subst "\* " "<\/b> "
subst " \[" "<img src=\"images\/"
subst "\] " "\" \/> "
# convert {.*|.*} into a link:
echo $( grep {.*} $out | sed -e 's/{\([^|}]*\)|\([^}]*\)}/<a href=\"\2\">\1<\/a>/g' ) > tmp2
mv tmp2 $out
#convert {.*} into a link:
echo $( grep {.*} $out | sed -e 's/{\([^}]*\)}/<a href=\"\1\">\1<\/a>/g' ) > tmp2
mv tmp2 $out
if [[ "$outfile" == "-" ]]; then
cat $out
rm $out
else
mv $out $outfile
fi
#eof!
hello, *this* is an _example_
it *should be able to _handle_ nested phrases*
it should handle *bold even through many* lines
and insert image: [image.jpg]
and create a hyperlink: {http://www.google.com} {http://www.wp.pl} {wirtualna _polska!_ |http://www.wp.pl} {google!|http://www.google.com}
this can be nested as well: *links: {http://www.google.com}*
---------------------------------------------------------------- testv2.sh ----------------------------------------------------------------
echo "## test suite"
function e {
x=exec $@ < example.txt
}
sc="./v2.sh "
cmd="$sc"
echo "# test 1: $cmd"
e $cmd
cmd="$sc --help"
echo "# test 2: $cmd"
e $cmd
cmd="$sc -h"
echo "# test 3: $cmd"
e $cmd
cmd="$sc -f"
echo "# test 4: $cmd"
e $cmd
cmd="$sc -f - "
echo "# test 5: $cmd"
e $cmd
cmd="$sc -f output "
echo "" > output
echo "# test 6: $cmd"
e $cmd
echo "printing the output file:"
cat output
rm output
echo "## end of test suite"