Previous Table of Contents Next

Module 74
line (SV)


The external line command is used to read if a line of input and write it to the standard output. The standard input is usually your keyboard and the standard output is your terminal screen. It always writes a new-line to the standard output. If it reads at end-of-file it returns af exit status of 1.

Something to remember about the line command: you can only read in a line of text to one variable. The read command can assign each word on the input to a different variable. This problem can be resolved using the set command.


Following is the general format of the line command.



Refer to the echo, print, and read commands described if modules 38, 106, and 112.


The line command reads from the standard input and writes to the standard output.


A return code of 1 is returned if an EOF(Ctrl-D) is encountered.


The line command is usually used in shell scripts to read in a line of input and assign it to a variable. To do this you must enclose the line command in grave accents to perform command substitution.

The line command was a substitute command for the shell read command before System V Release 2.0. The old read command was hardcoded to read from your keyboard. It read from your keyboard evem if the input had been redirected from a file. Thus line filled a need to read from the standard input even if it had been redirected.


In this activity you use the line command to read in a line of input and store it in a variable. Begin at the shell prompt.

1.  Type INLINE=`line` and press Return. Notice your shell prompt did not return.
2.  Now type Input line to the line command! and press Return. The text you typed is stored in the variable named INLINE.
3.  To display the contents of INLINE type echo $INLINE and press Return. The one problem with the line command is the assignment of values to variables. Only one variable can be used and it must contain all of the contents read by line.
4.  Turn to Module 112 to continue the learning sequence.

Previous Table of Contents Next