USDA ARS

Implementing IPW Commands as Scripts

Source File

An IPW command may be implemented as a shell script written for one of these interpreters:

A script has a source file which is a text file containing commands for a particular interpreter. The extension in the source file's name denotes which interpreter the script is written for: ".sh", ".awk", ".sed", or ".pl" (for perl). A sample source file for a "sh" script is provided with IPW: see the file "$(IPW)/src/samples/command/script.sh".

Makefile

The format Makefile for a script is quite simple:

    SCRIPT := foo.ext
    DESCRIPTION := blah blah blah

    include $(IPW)/make/command
The macro SCRIPT specifies the name of the script's source file. A sample of a script's Makefile is provided in the file "$(IPW)/src/samples/command/Makefile.script".

Making an executable version of the script

An executable version of the script is made from its source file by using the target "cmd":

    make cmd
The executable file has the same name as the source file, but without the extension. For example, if the source file is named "foo.sh", then the executable file is called "foo".

In accordance to Unix conventions, the first line of the executable file specifies the full path of the associated interpreter using the "#! " notation. The paths for all the interpreters are determined during the configuration phase of the installing IPW. The contents of this first line is determined by the source file's extension. For example, if the source file is named "foo.sh", then the executable file is called "foo", and has a first line which would look something like this:

    #! /bin/sh

The contents of the source file are copied into the executable after this first line. Each line is scanned for IPW macros, the most frequently used macro being "%description". This macro places the script's description from its Makefile into the executable file, so that it can be displayed in diagnostic messages.

Shell-support commands

Certain tasks are common among these scripts, and are encapsulated into separate supporting shell commands that can be invoked from any script. These support commands are located in IPW's library directory "$(IPW)/lib". Because this directory is typically not part of the search path for user commands, it must be added to to the PATH environment variable near the beginning of the script:

    PATH="$PATH:$IPW/lib"
An alternative is to specify the full path to a shell support command when invoking it:
    $IPW/lib/sherror $0 "You can't do that!"


IPW documentation / Last revised 20 May 2009 / IPW web site