How to use the read command in Bash?

前端 未结 8 1763
执念已碎
执念已碎 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:41

    Another alternative altogether is to use the printf function.

    printf -v str 'hello'
    

    Moreover, this construct, combined with the use of single quotes where appropriate, helps to avoid the multi-escape problems of subshells and other forms of interpolative quoting.

提交回复
热议问题