#!/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
body { font-family: serif; }
p { font-size: 13px; }
h2 { font-size: 24px;
font-style: italic;
}
ul { font-weight: bolder; }
<title>Index of ${dir}</title>
Index of ${dir}
$INDEX
EOI echo “Genrated index.html in ${dir}!” cd $cwd
#javascript#linux
About Hemanth HM
Hemanth HM is a Sr. Machine Learning Manager at PayPal, Google Developer Expert, TC39 delegate, FOSS advocate, and community leader with a passion for programming, AI, and open-source contributions.