LINUX.ORG.RU

Крик о помощи! Скрипт bash который меняет txt в html. Не запускается, помогите срочно!!

 


2

2

Скрипт который меняет 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!
----------------------------------------------------------------example.txt ----------------------------------------------------------------

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"



Последнее исправление: ypaseka (всего исправлений: 5)

Ответ на: комментарий от ypaseka

А раздела «Пунктуация» в твоём учебнике по русскому не было?

anonymous
()
Ответ на: комментарий от sin_a

я бы попросил ответы на курс физики, совсем на весь, но это не тема для лора ((( физика в программе есть, но она как была не нужна 10 лет назад, когда я первый раз поступал в универ, так и сейчас не нужна совершенно. Я не совсем представляю даже по какой траектории мячик падает, и это совершенно ни разу не пригодилось. А сдавать это говно сраное все равно нужно.

stevejobs ★★★★☆
()
Последнее исправление: stevejobs (всего исправлений: 1)
Вы не можете добавлять комментарии в эту тему. Тема перемещена в архив.