What's the difference between “here string” and echo + pipe

大憨熊 提交于 2019-11-30 19:41:28

In the pipeline, two new processes are created: one for a shell to execute the echo command, and one for a shell to execute the read command. Since both subshells exit after they complete, the x variable is not available after the pipeline completes. (In bash 4, the lastpipe option was introduced to allow the last command in a pipeline to execute in the current shell, not a subshell, alleviating the problem with such pipelines).

In the second example, no extra process is need for the here string (a special type of here document that consists of a single line), so the value of x is in fact set in the current shell, making it available for use later in the script/session.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!