Read

To capture input from the user, the read command is used to assign the characters entered on the command line to a variable:

#!/bin/bash

echo Please enter your name
read name
echo Hi $name, nice to meet you!

 

Multiple values may also be read:

#!/bin/bash

echo Please enter your fist and last names
read first last
echo Hi $first of the $last family, nice to meet you!

 

Use the -a option to instruct read to store the words in to an indexed array.

#!/bin/bash

echo Please enter a phrase
read -a myvar

for i in ${myvar[*]}
do
echo $i
done