HTML-generating Shell Scripts

Code Samples

Home > RefInfo menu > Computer topics menu >

This Handy Commands and Scripts Menu page >

This page of HTML Generating scripts

!Preliminary!
Some of these scripts may be changed someday
to be more complete (that is, to require less
follow up editing of the generated HTML file).

Also the scripts may be renamed to
a more consistent name format, reflecting
their organization into the groups on this page.

In early 2011, this preliminary page is intended
to get the code on the web, where I can access the
samples from my other computers, no matter where I am.

These scripts generate HTML that use 'table' elements
to format these pages. A more modern technique would be
to use 'div' elements --- but these scripts were made
when old browsers were not able to handle 'div' elements.

The 'yada yada yada' strings below are to be replaced
by more descriptive text. For now, the names of the
scripts --- and the comments at the tops of the scripts
--- will have to do for description.

Go to the Table of Contents, below.
(Skip the following Introduction.)

INTRODUCTION :

This is a page of Linux/Unix shell scripts (their code) which can be used to generate HTML pages for a given set of selected files in a directory.

These HTML-generating scripts are typically used in directories that contain

  • image files ('.jpg', '.gif', '.png', etc.)
  • seamless tiles image files
  • mp3 (audio) files
  • HTML files (skeletons/templates for making web pages)
  • mail files (to show examples of spam, for example --- by IP address)
  • scripts (like the ones below)

The HTML-generating scripts are grouped below in categories like those just listed. There is a table of contents below that you can use to go to the scripts --- or simply scroll down the page.

How to use these scripts :

You can open a text editor, highlight the code in one of these scripts, then copy and paste the text into the text editor. Then Save-As the code into a directory where you have the target files (images, mp3's, HTML files, or whatever).

You can run the script after changing the permission on the (script) file to make it executable. This can be done with a GUI. For example in the Gnome-Nautilus file manager, you can right click on the script file and choose 'Properties'. In the 'Properties' window that pops up, choose the 'Permissions' tab, and make sure the 'Allow executing file as program' checkbox is checked.

    You could also open a terminal window positioned in the directory of target files, where the script file now lies. You can use the 'chmod 755' or 'chmod o+x' command on the script file to make it executable. You can then run the script by typing a dot, a slash, and pasting the name of the script following the slash. Press enter to execute the script.

You can also run the HTML-generating script via a GUI. For example in the Gnome-Nautilus file manager, you can right click on the script file and choose 'Open' from the popup menu. In the window that opens, choose 'Run in terminal'.


Edit and Display of HTML built into the scripts :

The scripts are written to generate the HTML file in the current directory (the directory containing the target files). After the file is generated --- usually as a file named 'temp.html' --- the script puts the user in edit mode on the 'temp.html' file.

    The 'gedit' editor is generally used in the script, but you could change that to use another GUI text editor like 'scite' or 'kate' or whatever.

You can start editing some parts of the script without yet seeing how the page is displayed. When closing the editor, the 'temp.html' file is shown in a web browser. The script may use 'seamonkey', but you can change the script to use 'firefox' or whatever.

    You could also change the HTML-generating script, before running it, to put the web-browser startup BEFORE the text-editor startup. (Be sure to follow the web-browser command by the ampersand operator, to start the browser in the 'background'.)

    This way you can see the generated HTML page, rendered in the web browser window, from the 'temp.html' file, as you are editing the 'temp.html' file. You can use the 'Reload' option of the browser on the 'temp.html' file, after you make-and-save changes using the text editor.

After editing the 'temp.html' file to get it into more-or-less rough shape, you may wish to exit the editor and rename the 'temp.html' file.

    You may even want to relocate the HTML file, usually up a directory level. If you change its directory, remember to insert the appropriate sub-directory name in front of the names of the target files, in the links in the HTML file.

There is some further information on these HTML-generating scripts --- especially on how they are presented on this page --- below the Table of Contents, which starts just below.

Table of Contents:

(links to sections below on this page)

< Go to Top of Page, above. >

Scripts for showing image files, via direct links --- or via
generating thumbnail image files which serve as links to the full-size files :

Scripts for demo-ing seamless-tile image files :

Scripts for playing mp3 (audio) files, via web page links :

Scripts for displaying HTML (template) files :

Scripts for displaying mail files, such as examples of spam,
organized by their apparent source IP addresses :

Scripts for displaying (script) code samples, via web page 'object' links :

End of Table of Contents. See the 'file-safety' notes below.

How the code samples (below) are presented - and 'file-safety' notes :

Each of these HTML-generating script code samples is presented in this page as an HTML embedded plain-text 'object' so that you can scroll the text, vertically or horizontally.

Generally, in these shell scripts, I use double-# (##) to indicate a true comment. That is, it is not an executable script statement and should never be de-commented.

I use single-# (#) to indicate an executable statement that has been commented. Typically this is because I might want to decomment the statement when doing testing of the script in a terminal window. Generally, the statement should be re-commented --- or a neighboring statement should be commented --- when finished testing.

In essentially all of the scripts, you can scan the comments at the top of the scripts to see a description of their purpose --- and info on how they are to be used.

I do not try to make one-liner scripts, nor do I try for the ultimate in processing efficiency. (But I am aware of several things to avoid that would make scripts run slow as molasses.) Rather, I try to make the scripts readable (to me). At the same time, they execute quite rapidly, even on a directory containing over a hundred files. These scripts can be MAJOR time savers.

In most of these HTML-generating shell script samples, you will see that I am using the 'ls' command, together with a 'grep' for a particular file suffix, to 'pick up' the list of selected file names.

You will find that these code samples are NOT the 'be all and end all'. You (and I) will probably have to edit them somewhat to handle particular issues --- such as text formatting issues that were not considered when these scripts were written.


Navigation :

Use the table-of-contents (above) to go directly to the desired script code listing. OR simply scroll down this page to spot samples of interest.

Alternatively, use the 'Find text' option of your web browser to look for keywords on this page. For example, when looking for examples of scripts using the '<object ' HTML tag, use '<object ' --- or when looking for a script involving 'jpg' or 'gif' or 'mp3' files, use keyword 'jpg' or 'gif' or 'mp3'.


Shell considerations :

Most of these samples are intended to run with the Bourne or the Korn shells (command interpreters), as well as with the Bash command interpreter. Most of these samples employ Linux/Unix commands (and their parameters) available to all three interpreters, so the scripts will generally run in any of these three interpreters.

In fact, the Korn and Bash interpreters are offshoots of the Bourne command interpreter.


File-Safety :

Although I have used these scripts, I have used them, for the most part, on directories of files with no spaces (blanks) in the filenames. The scripts may not be tested thoroughly enough for every application environment. Use at your own risk.

    This may sound too dire. The scripts are generally quite safe. They do not change any of the files in the directory of 'target files'. The scripts simply generate a new HTML file in the directory.

    Examine the code, to erase doubt.

The HTML-generating code is presented here mostly for my own personal use --- as a reference (for example, from different computers, at home or away) and as a means of organized archival and backup. I may use portions of the scripts for tested code fragments to be applied in other HTML-generating scripts.

If other people use these scripts, they should test them on test data before using in a 'serious' mode.

FILE :
00_GEN_imgsDownHTMLpage_ jpggifFiles.sh.txt :

< Go to Table of Contents, above. >

Script for [description to go here] :

File is not shown. Technical difficulties.


FILE :
00_GEN_jpgLinks_ 4webpage.sh.txt :

< Go to Table of Contents, above. >

Script for [description to go here] :

File is not shown. Technical difficulties.


FILE :
00_GEN_imgTableCells4SMALLimgFiles.sh.txt :

< Go to Table of Contents, above. >

Script for [description to go here] :

File is not shown. Technical difficulties.


FILE :
00_GEN_imgTableCells4SMALLimgFiles_ NONrecursive.sh.txt :

< Go to Table of Contents, above. >

Script for [description to go here] :

File is not shown. Technical difficulties.


FILE :
00_GEN_imgTableCells4jpgfiles.sh.txt :

< Go to Table of Contents, above. >

Script for [description to go here] :

File is not shown. Technical difficulties.


FILE :
00_GEN_tableCells4medresImgFiles_ recursive.sh.txt :

< Go to Table of Contents, above. >

Script for [description to go here] :

File is not shown. Technical difficulties.


FILE :
00_GEN_tableCells4thumbANDimgFiles_ NONrecursive.sh.txt :

< Go to Table of Contents, above. >

Script for [description to go here] :

File is not shown. Technical difficulties.


FILE :
00_GEN_tableCells4thumbANDimgFiles_ recursive.sh.txt :

< Go to Table of Contents, above. >

Script for [description to go here] :

File is not shown. Technical difficulties.


FILE :
00_GEN_imgTableCells4jpggifFiles_ 1perRow.sh.txt :

< Go to Table of Contents, above. >

Script for [description to go here] :

File is not shown. Technical difficulties.


FILE :
00_GEN_imgTableCells4jpggifFiles_ 6perRow.sh.txt :

< Go to Table of Contents, above. >

Script for [description to go here] :

File is not shown. Technical difficulties.


FILE :
00_GEN_jpgfilesList.sh.txt :

< Go to Table of Contents, above. >

Script for [description to go here] :

File is not shown. Technical difficulties.


FILE :
00_GEN_tableCells4SMALLaniGifFiles_ recursive.sh.txt :

< Go to Table of Contents, above. >

Script for [description to go here] :

File is not shown. Technical difficulties.


FILE :
00_GEN_jpgfilesSlideshowList.sh.txt :

< Go to Table of Contents, above. >

Script for [description to go here] :

File is not shown. Technical difficulties.


FILE :
00_GEN_tileDemoPages_ inSubdir.sh.txt :

< Go to Table of Contents, above. >

Script for [description to go here] :

File is not shown. Technical difficulties.


FILE :
00_GEN_tilePages.sh.txt :

< Go to Table of Contents, above. >

Script for [description to go here] :

File is not shown. Technical difficulties.


FILE :
00_GEN_tileTableCells4SMALLtileFiles.sh.txt :

< Go to Table of Contents, above. >

Script for [description to go here] :

File is not shown. Technical difficulties.


FILE :
00_GEN_mp3fileLinks_ 4webpage.sh.txt :

< Go to Table of Contents, above. >

Script for [description to go here] :

File is not shown. Technical difficulties.


FILE :
00_GENfindALL_mp3fileLinks_ 4webpage.sh.txt :

< Go to Table of Contents, above. >

Script for [description to go here] :

File is not shown. Technical difficulties.


FILE :
00_find_mp3s_ fromHere.sh.txt :

< Go to Table of Contents, above. >

Script for [description to go here] :

File is not shown. Technical difficulties.


FILE :
00_GEN_htmFilesList.sh.txt :

< Go to Table of Contents, above. >

Script for [description to go here] :

File is not shown. Technical difficulties.


FILE :
00_GEN_spamfileLinks_ 4webpage.sh.txt :

< Go to Table of Contents, above. >

Script for [description to go here] :

File is not shown. Technical difficulties.


FILE :
00_GEN_spamfileLinks_ 4webpage_ findALL.sh.txt :

< Go to Table of Contents, above. >

Script for [description to go here] :

File is not shown. Technical difficulties.


FILE :
00_GEN_objectsDownHTMLpage_ txtFiles_ withTOC.sh.txt :

< Go to Table of Contents, above. >

Script for [description to go here] :

File is not shown. Technical difficulties.


FILE :
00_GEN_scriptFileLinks_ 4webpage.sh.txt :

< Go to Table of Contents, above. >

Script for [description to go here] :

File is not shown. Technical difficulties.

Bottom of this
HTML-generating Scripts --- Code Samples page.

To return to a previously visited web page location, click on the Back button of your web browser, a sufficient number of times. OR, use the History-list option of your web browser.
OR ...

< Go to start of Script Code display, above. >

< Go to start of Table of Contents, above. >

< Go to Top of Page, above. >

Page was created 2011 Jan 05.

Page was changed 2011 Jun 06.

Page was changed 2018 Sep 01. (Added css and javascript to try to handle text-size for smartphones, esp. in portrait orientation.)