Explanation of fols

[previous] [next] [table of contents] [index]

Section List Folders in Columns with fols gives an overview of this script. Here is the fols script (you might want to open it in a separate browser window). To install it, see Section Programs in This Book's Archive.

The archive has a new version of fols, the program that's shown in the Section Writing Shell Scripts for MH. fols prints the folders -fast output in columns. The case statement checks the command line. It catches errors in the number of arguments or the contents of $1. The $#$1 pattern, the number of command-line arguments and the contents of $1 (if any), is matched against the corresponding patterns. If there are no arguments, or if there's exactly one argument and it starts with -r, the test succeeds. That may look tricky, but it's really simple. A two-line sed command reads the output of folders. There are two sed expressions (with -e before each). The first expression puts a plus sign (+) after the current folder name; it uses folder -fast, inside backquotes, to find the current folder (foldername). The second expression only matches lines that are longer than 18 characters (which is how wide the pr -4 -l78 command makes its columns). It takes the first eight characters and the last nine characters of a folder name, ignores the middle -- then outputs the two pieces with an equal sign (=) between them. This makes an 18-character-long folder name with an = replacing what's been cut out. Not all UNIX systems have programs especially designed to write output in columns, but all systems should have pr. Here, it's used to make columns by giving a page length of 1 (-l1) with no headers (-t), a line 78 characters wide (-w78), and four columns (-4). The page length of 1 with four columns means that pr will read four lines of input, spread them left-to-right across the line, and then output it.

[Table of Contents] [Index] [Previous: The execit Programs] [Next: Explanation of mhprofile]


Last change $Date: 1996/06/06 15:09:45 $

This file is from the third edition of the book MH & xmh: Email for Users & Programmers, ISBN 1-56592-093-7, by Jerry Peek. Copyright © 1991, 1992, 1995 by O'Reilly & Associates, Inc. This file is freely-available; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation. For more information, see the file copying.htm.

Suggestions are welcome: Jerry Peek <jpeek@jpeek.com>