How to generate html bar chart in bash

enthuguy
enthuguy used Ask the Experts™
on
Hi Experts,
How to generate simple html bar chart in bash based on 3 input values. (without CSS) please

Scenario is, we will provide 3 arguments to function and it should generate a text

Please check the attached the html file which produces this chart and a screen shot with explanations.

Have used below online editor
https://html-online.com/editor/

Please help, thanks in advance.
bash_html.jpg
HowTo_bash_html_bar_chart.txt
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
A simple loop to print each bar:

BARLENGTH=$1
BARCOLOR="#98FB98"
COUNT=1
while [ $COUNT -le $BARLENGTH ]
do
  printf '<td BGCOLOR="' >> gen_html.html
  printf "$BARCOLOR" >> gen_html.html
  echo '"> </td>' >> gen_html.html
  COUNT=$(( $COUNT + 1 ))
done
printf '<td>' >> gen_html.html
printf "$BARLENGTH" >> gen_html.html
echo '</td>' >> gen_html.html
The scriptlet works, and is the hardest part of the task; I would have been happy to advise further, but not write a complete script as it sounded like possible homework

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial