When I try to use the read command in Bash like this:
read
echo hello | read str echo $str
Nothing echoed, while I think str should contain the string hello. Can anybody please help me understand this behavior?
str
hello
Typical usage might look like:
i=0 echo -e "hello1\nhello2\nhello3" | while read str ; do echo "$((++i)): $str" done
and output
1: hello1 2: hello2 3: hello3