read builtin

The bash builtin that reads one line of input and stores it, or its fields, in variables.

In more detail

Always use -r, or backslashes in the input are treated as escapes and disappear. Put IFS= in front to keep leading and trailing spaces, and redirect the file after done so a while loop reads it line by line. -p shows a prompt and -a reads the fields into an array.

Examples

read -r -p "Your name: " name
while IFS='=' read -r key value; do echo "$key"; done < config.env

Related terms

Taught in

References