The read builtin pauses the script, waits for input from stdin, and stores the entered text in the specified variable-in this case USERNAME. Commands such as echo only display text, source executes another file in the current shell, and grep searches existing files; none of these capture live keyboard input, making read the only appropriate choice for this task.
Ask Bash
Bash is our AI bot, trained to help you pass your exam. AI Generated Content may display inaccurate information, always double-check anything important.
How does the `read` command work in a shell script?
Open an interactive chat with Bash
What happens if the user doesn’t enter any input when using the `read` command?
Open an interactive chat with Bash
Can the `read` command be used to accept multiple inputs at once?