Read Keyboard Input Command - Exercise
Using read to Collect Keyboard Input
Objective: Use the read command to collect user input and store it in a variable.
Exercise Scoring
This exercise is worth 3 points.
Background
You should have an account on the DispersedNet Labs server or on a Unix/Linux system at your site.
Log in so you have access to a command-line prompt. This exercise uses the Bourne shell (sh) to keep syntax consistent.
Instructions
- Log in to your Unix account and confirm you are working at a command prompt.
- Start a Bourne shell so your commands match what you would use inside a Bourne-compatible script:
% sh
- Read one line of user input into a variable named
DOWNLOADFILE:
$ read DOWNLOADFILE
- The cursor moves to the next line and waits for input. Type a filename (any name you make up is fine), then press Enter.
- The prompt returns, but you may not see any feedback yet. Display the variable value using
echo and a dollar sign:
$ echo $DOWNLOADFILE
- You should see the exact value you typed in step 4.
- Now run
echo again without the dollar sign to see the difference between a variable value and plain text:
$ echo DOWNLOADFILE
- You should see the literal word
DOWNLOADFILE printed to the screen.
In the textbox below, paste the key lines of your terminal session that demonstrate the workflow.
At minimum, include the commands and output for:
read DOWNLOADFILE, echo $DOWNLOADFILE, and echo DOWNLOADFILE.