Generate index.html for a given directory

!/bin/bash

Author : Hemanth.HM

Email : [email protected]

Purpose : To genrate index.html for a give directory.

Usage : bash index.sh

dir=$1 cwd=$PWD

Check for input

[ -z ${dir} ] && echo "Usage : basename $0

" && exit 1 || cd ${dir}

In case the user gives the input as "."

[ "${dir}" == "." ] && dir=pwd

Collect each file and add them to href's

INDEX=$(for f in *; do printf '

  • %s
  • \n' "$f" "$f"; done)

    Create an index.html file

    cat > index.html << EOI