Unix Shell Scripts
Unix Shell Available
Determining Unix Shell
Shell Scripts Unix
Interpreted Compiled Programs
Understanding Scripting Options
Shell Script Macro
Built in Components
Input Output Tools
Shell Script Tests
Regex Define Patterns
Shell Program Components
Writing First Script
Interactive Shell Script
Defining Script File
Using Text Editor
Read Input Command
Including Comments Scripts
Setting File Permissions
Running Command Line
Working With Variables
Command Line Arguments
Predefined System Variables
Syntax Affects Interpretation
Using Strings Variables
Performing Math Variables
Using Array Variables
Read Keyboard Input Command - Exercise
Using the read command to read keyboard input
Use the read command to collect user input in a script.
This exercise is worth 3 points.
You should have an account set up on the DistributedNetworks Labs server or on a UNIX server at your site. Log in to this account so you see a UNIX command line prompt. We will do this exercise with the Bourne shell.
Log in to your UNIX account so that you are working at a command prompt.
At the command line, enter this command to start a Bourne shell, so that the commands used at the command prompt will match what you do in a Bourne shell script.
At the command line, enter this command to read a line of user input:
$ read DOWNLOADFILE
The cursor moves to the next line and waits. The prompt does not reappear. Type a filename (something that you make up is fine) and press Enter.
The prompt returns but you see no other feedback. The variable, however, was set to the value that you entered. To see this, enter the following command at the command-line prompt:
$ echo $DOWNLOADFILE
You see the value that you typed in during step 3.
The dollar sign indicates to the
command that the text is a variable name. Enter this command to see how
responds without the dollar sign:
$ echo DOWNLOADFILE
You see the word DOWNLOADFILE printed to the screen.