Skip to content
Justice Tech School

Reading Input

read stores a line in a variable. -r keeps backslashes, -p shows a prompt and -a reads into an array. Here input is piped for repeatable output.

Example
echo "Ada 30" | { read -r name age; echo "$name is $age"; }
read -ra parts <<< "a b c"
echo "${#parts[@]} ${parts[1]}"

Result

Ada is 30
3 b

Exercise

Read a line.

 -r line

Quiz Test

What does -r do?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.