Re: Detecting file type extension in a bash script on linux
From: Chris F.A. Johnson (c.fa.johnson_at_rogers.com)
Date: 01/16/04
- Next message: steve_at_remove.zinck.ca: "Re: query user's group"
- Previous message: Ed Morton: "Re: query user's group"
- In reply to: B Thomas: "Detecting file type extension in a bash script on linux"
- Next in thread: William Park: "Re: Detecting file type extension in a bash script on linux"
- Reply: William Park: "Re: Detecting file type extension in a bash script on linux"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 16 Jan 2004 21:18:58 GMT
On Fri, 16 Jan 2004 at 10:17 GMT, B Thomas wrote:
> Hi,
> I am trying to write a script that generates a html index of a
> directories contents. For this the scripts needs to detect the type of
> file (file extension) and accordingly put appropriate html code for an
> icon of that file type besite the file name. How may I do this ?
> sincerely
{
echo "<html>
<head>
<title>Index of $PWD</title>
</head>
<body><ul>"
for file in *
do
case $file in
*.exe) img=exe.png; type="MS executable" ;;
*.gif) img=gif.png; type="GIF image" ;;
*.tgz|*.tar.gz) img=tgz.png; type="gzipped tar archive" ;;
*.ps) img=postscript.png; type="PostScript file" ;;
*[-.]sh) img=shell.png; type="shell script";;
## etc....
*) type=unknown; img=default.png ;;
esac
printf "<li><a href=\"%s\">" "$file"
printf "<img src=\"%s\" alt=\"%s\">\n" "$img" "$type"
done
printf " </ul>\n </body>\n</html>"
} > index.html
--
Chris F.A. Johnson http://cfaj.freeshell.org
===================================================================
My code (if any) in this post is copyright 2004, Chris F.A. Johnson
and may be copied under the terms of the GNU General Public License
- Next message: steve_at_remove.zinck.ca: "Re: query user's group"
- Previous message: Ed Morton: "Re: query user's group"
- In reply to: B Thomas: "Detecting file type extension in a bash script on linux"
- Next in thread: William Park: "Re: Detecting file type extension in a bash script on linux"
- Reply: William Park: "Re: Detecting file type extension in a bash script on linux"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|