Text-only Table of Contents (frame/ no frame)
(15) Input and output Previous Top Next

Input and Output

Shell scripts can generate output directly or read input into variables using the following commands:

Script output

echo
Print arguments, separated by spaces, and terminated by a newline, to stdout. Use quotes to preserve spacing. Echo also understands C-like escape conventions. Less detail
Beware that the shell may process backslashes before echo sees them (may need to double backslash). Internal in most shells, but was originally external.
\b backspace \c print line without new-line (some versions)
\f form-feed \n new-line
\r carriage return \t tab
\v vertical tab \\ backslash
\0n where n is the 8-bit character whose ASCII code is the 1-, 2- or 3-digit octal number representing that character.
-n
suppress newline
print (ksh internal)
Print arguments, separated by spaces, and terminated by a newline, to stdout. Print observes the same escape conventions as echo.
-n
suppress newline
-r
raw mode - ignore \-escape conventions
-R
raw mode - ignore \-escape conventions and -options except -n.

Script input

read var1 var2 rest
read a line from stdin, parsing by $IFS, and placing the words into the named variables. Any left over words all go into the last variable. A '\' as the last character on a line removes significance of the newline, and input continues with the following line.
-r
raw mode - ignore \-escape conventions

Example: ex4a display, text


Previous Top Next


stdio.src  last modified Jun 9, 2006 Introduction Table of Contents
(frame/no frame)
Printable
(single file)
© Dartmouth College