Cover V04, I03
Article
Listing 1
Listing 2
Sidebar 1
Sidebar 2

may95.tar


Sidebar: Here Documents

Here Documents allow shell scripts to accept input redirection from external sources, such as the command line, ed, or SQL*Plus.

The syntax for a Here Document using ed is:

ed - <filename> << xxUNIQUE_STRINGxx
g/January/s//February/g
.
w
q
xxUNIQUE_STRINGxx

In this example the calling script passes execution to the ed editor. ed opens the file <filename> and executes all commands found between the two occurrences of xxUNIQUE_STRINGxx (in this case it will change all occurrences of "January" to "February," then save and quit ed). Execution then returns to the calling shell script.

The syntax for a Here Document using SQL*Plus is:

sqlplus <DBUSERID>/<PASSWORD>@<DATABASE> << xxUNIQUE_STRINGxx
SELECT * FROM USER_CATALOG;
quit
xxUNIQUE_STRINGxx

In this example the calling script passes execution to SQL*Plus. SQL*Plus connects to the specified database and executes all the commands enclosed between the two occurrences of xxUNIQUE_STRINGxx (in this case SQL*Plus would simply select everything from the user's catalog). Because the output is not redirected, it will be displayed on the screen. The Here Document then exits and returns execution to the calling shell script.

Note that the terminating xxUNIQUE_STRINGxx must begin in column one.

For a good explanation of Here Documents, see O'Reilly & Associates' UNIX Power Tools , 1993.