[Bash] Read one line from standard input

Created on November 30, 2026

Use read to read one line into a variable. The here string operator <<< supplies the sample as standard input.

read -r line <<< 'hello world'
printf '%s\n' "$line"
hello world

-r keeps backslashes literal. The variable line holds the text read from input.

Reference

Bash Shell command