|
|
< Day Day Up > |
|
10.2. Reading User Input10.2.1 The $< VariableTo make a script interactive, a special C shell variable is used to read standard input into a variable. The $< symbol reads a line from standard input up to but not including the newline, and assigns the line to a variable.[1]
Example 10.3.
(The Script - greeting)
#/bin/csh -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, Dan Savage.
EXPLANATION
10.2.2 Creating a Wordlist from the Input StringBecause the input from the $< variable is stored as a string, you may want to break the string into a wordlist. Example 10.4.1 % echo What is your full name\? 2 % set name = $< Lola Justin Lue 3 % echo Hi $name[1] Hi Lola Justin Lue 4 % echo $name[2] Subscript out of range. 5 % set name = ( $name ) 6 % echo Hi $name[1] Hi Lola 7 % echo $name[2] $name[3] Justin Lue EXPLANATION
|
|
|
< Day Day Up > |
|