Tsallaka zuwa abun ciki
Justice Tech School

Reading Input

read stores a line into a variable. -p shows a prompt, -s hides typing and -t sets a timeout. The example feeds the input from a here string.

Example
read -r name <<< "Ada"
echo "Hello $name"
read -r a b <<< "one two"
echo "$b $a"
while read -r line; do echo "> $line"; done <<< $'x\ny'

Result

Hello Ada
two one
> x
> y

Exercise

Prompt option.

read  "Name: " n

Quiz Test

What does read -s do?

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