How to read multiple words in linux bash script
I am prompting the user to enter two words separated by space.
I am using read name
to read name and then read last
to read last word
the user inputs like name last
separated by space. But read seems to be reading the
whole line. How can I read the first words and the second word separately?
In general, you can read into an array.
$ read -ra arr
sadf / asdf \ wer
tomasz@fuji:~$ printf "%s\n" "${arr[@]}"
sadf
/
asdf
\
wer
Each line in this printf output corresponds to a single array item.