Concept Flow - read command
Start Script
Prompt User
Wait for Input
Store Input in Variable
Use Variable
End Script
The read command waits for user input, stores it in a variable, then the script uses that input.
echo "Enter your name:" read name echo "Hello, $name!"
| Step | Action | Input/Condition | Variable State | Output |
|---|---|---|---|---|
| 1 | Print prompt | N/A | name = '' | Enter your name: |
| 2 | Wait for user input | User types 'Alice' | name = '' | |
| 3 | Store input in variable | Input 'Alice' | name = 'Alice' | |
| 4 | Print greeting | name = 'Alice' | name = 'Alice' | Hello, Alice! |
| 5 | End script | N/A | name = 'Alice' | Script ends |
| Variable | Start | After Step 2 | After Step 3 | Final |
|---|---|---|---|---|
| name | '' (empty) | '' (waiting input) | 'Alice' | 'Alice' |
read command syntax: read variable_name Behavior: - Pauses script to get user input - Stores input in the variable - Continues script using that input Key rule: User must press Enter to finish input.
read command do in a bash script?readread command pauses the script and waits for the user to type something.username?read variable_name without any special characters.read username, which correctly stores input in username. Others misuse flags or symbols.echo "Enter your age:"
read age
echo "You are $age years old."
age, then prints a message using that input.read -p "Enter your city: " city
echo "City is $city"
-p option allows showing a prompt before reading input, which is valid in bash.city is correctly placed after the prompt, and quotes around prompt text are correct.first and last, from one line of user input separated by space. Which command correctly does this?read command can take multiple variable names to split input by spaces.read first last to read two words into two variables. read -p first last misuses -p. read first; read last reads twice separately. read -a first last uses -a incorrectly here.Pass the test and this pattern moves unknown