read

Read input from stdin or user prompt into shell variables.

low risk

interactive breakdown — edit the command and press Explain
$ 
⚠ Risks & cautions
What it does

read captures user input or reads lines from stdin into shell variables. Used for interactive scripts, parsing file content line-by-line, and prompting for secrets (with -s to disable echo). The -r flag prevents backslash interpretation.

Common flags
FlagMeaning
-r --rawRaw mode: don't interpret backslashes
-s --silentSilent mode: don't echo input (for passwords)
-p --promptPrint prompt before reading
-t --timeoutTimeout in seconds
-a --arrayRead words into an array
Examples
read -p 'Enter cluster name: ' CLUSTERInteractive prompt with variable capture · explain & risk-check →
read -s -p 'Password: ' PASSSilent password prompt · explain & risk-check →
while IFS=: read -r user _ uid _; do echo "$user uid=$uid"; done < /etc/passwdParse /etc/passwd field by field · explain & risk-check →
read -r -t 10 -p 'Continue? [y/N] ' responsePrompt with 10-second timeout · explain & risk-check →
Pro tip

Always use `IFS= read -r line` when reading file lines — prevents leading/trailing whitespace stripping and backslash interpretation that causes subtle bugs.

Related
printf test source
Open the full explainer →More in Shell & Scripting

Reference text is hand-written and may be incomplete — check man read for your version. Test destructive commands on a non-production system first.