Input

Many UNIX programs are interactive and read input from the user. To use such programs in shell scripts, you need to provide them with input in a non-interactive manner. Also, scripts often need to ask the user for input in order to execute commands correctly.

To provide input to interactive programs or to read input from the user, you need to use input redirection. In this section, you will look at the following methods in detail:

  • Input redirection from files

  • Reading input from a user

  • Redirecting the output of one command to the input of another

Input Redirection

When you need to use an interactive command, such as mail in a script, you need to provide the command with input. One method for doing this is to store the input of the command ...

Get Sams Teach Yourself Shell Programming in 24 Hours, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.