gpt4 book ai didi

linux - 为什么 "echo foo | read a ; echo $a"没有按预期工作?

转载 作者:IT王子 更新时间:2023-10-29 00:23:00 25 4
gpt4 key购买 nike

我可以在 FreeBSD、GNU/Linux 和 Solaris 下使用各种 shell 重现该问题。这让我挠头了一个多小时,所以我决定在这里发布问题。

最佳答案

由于管道,read 在其自己的子 shell 中执行。

echo foo | while read a; do echo $a; done

会按照您的期望去做。

关于linux - 为什么 "echo foo | read a ; echo $a"没有按预期工作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/374687/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com