How to use the read command in Bash?

前端 未结 8 1764
执念已碎
执念已碎 2020-12-07 23:54

When I try to use the read command in Bash like this:

echo hello | read str
echo $str

Nothing echoed, while I think str<

8条回答
  •  独厮守ぢ
    2020-12-08 00:58

    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
    

提交回复
热议问题