How to use the read command in Bash?

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

    To put my two cents here: on KSH, reading as is to a variable will work, because according to the IBM AIX documentation, KSH's read does affects the current shell environment:

    The setting of shell variables by the read command affects the current shell execution environment.

    This just resulted in me spending a good few minutes figuring out why a one-liner ending with read that I've used a zillion times before on AIX didn't work on Linux... it's because KSH does saves to the current environment and BASH doesn't!

提交回复
热议问题