Initially Speaking

Many Unix programs let you customize the way they run upon start-up. They can do this in a number of ways, including the use of command line options, environment variables, and initialization files.

The simplest way to specify options for a command is through command line options. This technique has already been discussed in the context of regular Unix commands (see Tipsheet Vol. 1, No. 4) but applies equally to other programs that have been added to our Unix setup. For instance, we have installed the program "zip" (and its partner, "unzip") onto Bama, which makes a compressed, file archive. It can do a variety of different tasks and behave in a variety of ways related to making the zipped-up archive. To see the list of options just type "zip" and press "enter". Suppose that you want "zip" to always be verbose (tell you what it is doing) and you always want to zip up files by following directories recursively (following through in subdirectories to look for more files and subdirectories). Then you would run the command as

zip -v -r filelist

where filelist is the list of files or directories you want to archive. Having to do this seems simple enough, but once you get to the point of having to look up how to run a command over and over again to find the same options, you'll want to find a way to set it and forget it. Which brings us to the next technique: environment variables.

Many programs will let you specify options in an environment variable. The one for "zip" happens to be called ZIPOPT. So, to specify options that will always be used for zip you would type:

ZIPOPT="-v -r"
export ZIPOPT

Just put these two lines in your ".profile" (see Tipsheet Vol. 1, No. 3 ) and every time you log it, the options will be set. Note that you will occasionally find programs that require that environment variables be set. This information is always included in the man pages.

The next question probably would be, "How does one know what environment variable to use?" The answer is, "Look in the man page." Almost all the software that we have loaded onto Bama comes with a help page accessible by typing

man progname

where progname is the name of the program. These help files can be long and confusing, but if you can manage to keep on reading you will come across the places where they discuss any relevant environment variables.

An example of another common program that uses an environment variable for setup is "vi". Its environment variable is called EXINIT. Here is a sample setup.

EXINIT="set wrapmargin=8 | map t xp"
export EXINIT

This particular example sets up "vi" to do a word wrap at 8 characters before the end of the line, and it maps the "t" key while in edit mode (that's the mode where you've pressed "escape"), to transpose two characters. The latter function is normally done by pressing "x" and then "p". Now "vi" has a huge number of options you might want to set. In particular, the ability to map keys to do special actions, like the "t" example here, is quite attractive. Once you start to think about it, there could be hundreds of key mappings you could do (or at least, lots). At that point, the information becomes too long for the environment variable and we move to the next technique; initialization files.

The "vi" editor uses an initialization file called ".exrc", that is put in your home directory. You create this file with any editor. The same commands that would have gone into EXINIT can be put, one command to a line, in ".exrc". Whenever you start editing with "vi", then, the program looks for EXINIT. If that is not set, it looks for the file ".exrc" in your home directory. How do you know what the initialization program is called? Go back to the man pages again. Type

man vi

and you'll learn more about "vi" than you ever wanted to know.

There are some programs that have such complicated initialization files that they don't recommend, or even want, for you to edit the file yourself. One example of this is Pine, the mail program. Its initialization file is called ".pinerc". All changes to it can be done through the setup-config options in Pine. You can still edit this file by hand, but be wary of mistakes. If you get it too fouled up, you'll have to delete it and redo the configuration using Pine again. The initialization file created by the Sun Workshop program (the program compiling/debugging suite of software), called ".workshoprc", definitely says, "DO NOT EDIT!"

Most complex programs have the ability to read initialization files. This includes all the editors we have, the compilers, and some of the specialized text formatting programs. How do you know how to proceed with setting up initializations? Start by using the program for a while, and then think about the options that you find most useful. These are the ones that need to be initialized somehow. Go the man pages and read-up on where they need to go; in an environment variable, in an initialization file, or just on the command line.

 

© 1999, The University of Alabama. The information included here is for the University of Alabama central computing facility as it was configured on the document date. It may or may not apply to other Unix systems.