I need to split a single line containing multiple words separated by spaces returned by a command. I tried using read but it acts completely strange. For example:
Why does running echo "Hello World!" | read -ra lines; echo "${lines[@]}" in Bash results in an empty line, but running echo "Hello World!" | read -ra lines; do echo "${lines[@]}"; done results in Hello World!?
If I run echo "Hello World!" | tee /dev/stdout | read -ra lines; echo "${lines[@]}" it also results in an empty line.
Even simple echo "Hello World!" | read hello; echo "$hello" doesn't work.