Bash script to extract HTML comment into a Markdown file I learned Bash a million years ago. I just wrote this simple script used to get the first lot of HTML comments from a file, and spit it out in order to create a README.md file.

It is just. So. Ugly. I read bits and pieces over the years, and I am sure it can be improved so much...

Here we go:

#!/bin/bash

IFS=''
active='0';
cat  hot-form-validator.html | while read "line";do

  echo $line | grep '\-\-&gt;' &gt; /dev/null
  if [ $active = '1' -a $? = '0' ];then 
    exit 0;
  fi;

  suppress=0;
  echo $line | grep '^ *@' &gt; /dev/null
  if [ $? = '0' ];then suppress='1'; fi;


  if [ $active = '1' -a $suppress = '0' ];then echo $line;fi;

  echo $line | grep "&lt;!--" &gt; /dev/null
  if [ $? = '0' ];then active='1'; fi;

done


Questions:


Is there a better way to do grep and then check $??  Back in the day it was the way to go, but...
Should active be a proper number rather than a string with a number? I  know, it could be anything... but having a string that can be 0 or 1 just feels wrong.
Is there a better way to preserve spaces, rather than zapping IFS?
Any more pearls of wisdom, other than quitting my (short lived) career of bash scripter?
A bug


If your html contains a backspace character e.g

&lt;p&gt;The special character \n is a way to include read line&lt;/p&gt;


your code interprets it a


  The special character n is a way to include read line.


to avoid this, add "-r" switch to your read line

cat  hot-form-validator.html | while  read -r "line";do


You want to check if your file exists before reading it



if [ -f $filename ]; then
#do something
else
#do something
fi