IT 3110 : Advanced System Administration

Standard input

Review

Getting input from a file

  • wc < foo.txt
  • Many shell commands will take one or more filenames as arguments, but when no filename is given will read from standard input.

User input

You can use the read statement to get information from the users.

  • read -p "What is your name?" name
    • creates variable called name
  • read a b c
  • In its simplest form, a read statement with no arguments will read user input and place it into the shell variable REPLY.
  • Can use these in scripts later.

Easy menu generation

Can use the select statement like:

    select a in b c d; do echo $a; done

Heredoc

A here document (Heredoc) is a type of redirection that allows you to pass multiple lines of input to a command.

The syntax of writing HereDoc takes the following form:

[COMMAND] <<[-] 'DELIMITER'
HERE-DOCUMENT
DELIMITER