DispersedNet
SiteMap
Unix Concepts
Shell Programming
Shell Scripting
Unix Questions
Unix Shell Scripts
«Prev
Shell Programming
Shell Programming
Unix Shell Available
Determining Unix Shell
Shell Scripts Unix
Interpreted Compiled Programs
Understanding Scripting Options
Cmpiled Programs
Shell Components
Shell Script Macro
Built in Components
Input Output Tools
Shell Script Tests
Script Variables
shell-script-control-structures
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
Using Positional Variables
Predefined System Variables
System Variables
Environment Variables
Syntax Affects Interpretation
Using Strings Variables
Using Numbers-inVariables
Performing Math Variables
Using Array Variables
Scripts Variable Summary
Designing Scripts
Script Objective
Script Flow
loop Tests
Checking Commands
error Trapping
Making Script Portable
Documenting Script
Designing Shell Scripts
Read Keyboard Input Command - Exercise
Using read command to read Keyboard Input
Objective:
Use the read command to collect user input in a script.
Exercise scoring
This exercise is worth 3 points.
Background/overview
You should have an account set up on the DispersedNet 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.
Instructions
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.
% sh
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
echo
command that the text is a variable name. Enter this command to see how
echo
responds without the dollar sign:
$ echo DOWNLOADFILE
You see the word DOWNLOADFILE printed to the screen.