11.2. Reading User Input

11.2.1. The $< Variable

To make a script interactive, a special TC shell variable is used to read standard input into a variable. The $< symbol reads a word from standard input up to the first white space but not including the newline, and assigns the word to a variable. By placing $< in double quotes (or parentheses)[1], a whole line is read, not including the newline.

[1] The C shell does not rerquire double quotes around the $< variable to read a whole line.

Example 11.4.
(The Script - greeting)
   #!/bin/tcsh -f
   # The greeting script
1  echo -n  "What is your name? "
2  set name = "$<"
3  echo Greetings to you, $name.

(The Command Line)
   > chmod +x greeting
   > greeting
1  What is your name?
						Dan Savage
3  Greetings to you, ...

Get Linux Shells by Example 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.