Current Issue


Table of contents

CD-ROM

Sys Admin and The Perl Journal CD-ROM version 12.0

Version 12.0 delivers every issue of Sys Admin from 1992 through 2006 and every
issue of The Perl Journal from 1996-2002 in one convenient CD-ROM!

Order now!

Sys Admin Magazine > Archives > 1992 > 9204
Listing 1 Listing 2

In-Line Input or Bust

Leor Zolman

All standard UNIX shells support a nifty method for embedding standard input data within the very shell script that reads that data. The syntax for using such in-line input is as follows:

command-name parameters <<-END
input line 1
input line 2
.
.
.
input line n
END

With this form of the construct, all text between the END markers (any text pattern may be used in place of END) is fed to the standard input of the command-name command. The hyphen before the first END says to strip all whitespace from the beginning of each line of the input data; this allows the source text to be formatted with arbitrary indentation for clarity, even when such indentation might confuse the command that will actually read the input.

To see the technique in action, submit the following command to your shell:

wc <<-STOP
this is
a
test
STOP

The system should respond with:

3  4  15

So far, this is all basic shell stuff. Any command that accepts data on its standard input stream can be supplied with in-line data using this technique. However, what do you do with a program that does not accept any input from the standard input stream, but only knows how to take its input from a physical file named on the program's command line? The only way to feed literal input to such a program is to manually create a temporary file containing the required text, run the program with the name of that file as a parameter, and then remove the temporary file after the program has finished running.<>




MarketPlace

FREE Trial Download Speeds Up Systems Now!
New Diskeeper 2008 Maximizes System Performance and Reliability�Automatically!

Instant Answers to Your IT & Business Questions
Sign Up & Get Full Access To The Definitive Online Book Collection With SkillSoft's Books24x7�.

BugSplat - Automatic Crash Analysis
Fast online exception analysis. Capture customer crash data online.

WinDev 12 - Powerful IDE
Develop 10 times faster ! ALM, IDE, .Net, RAD, 5GL, Database, 5GL, 64-bit, etc. Free Express version

Wanna see your ad here?