html

Generate index.html for a given directory

  1. #!/bin/bash
  2. #Author : Hemanth.HM
  3. #Email : hemanth.hm@gmail.com
  4. #Purpose : To genrate index.html for a give directory.
  5. #Usage : bash index.sh <dir>
  6.  
  7. dir=$1
  8. cwd=`pwd`
  9.  
  10. #Check for input
  11. [ -z ${dir} ] && echo "Usage : `basename $0` <dir>" && exit 1 || cd ${dir}
  12.  
  13. # In case the user gives the input as "."
  14. [ "${dir}" == "." ] && dir=`pwd`
  15.  
  16.  
  17. # Collect each file and add them to href's
  18. INDEX=`ls -1 ${dir} | sed "s/^.*/ <li\>\<a\ href=\"&\"\>&\<\\/a\>\<\\/li\>/
  19.  
  20. # Create an index.html file
  21. cat > index.html << EOI
  22. <html>
  23. <head>
  24. <style type="text/css">
  25.