为什么 source 命令在 bash 3.2 中不能与进程替换一起使用?

Why source command doesn't work with process substitution in bash 3.2?

我有以下 shell 脚本:

cat <(echo foo)
source <(echo bar=bar)
echo $bar

但是它在 GNU bash 3.2 和 4.3 中的工作方式不同,如下所示:

$ /bin/bash foo.sh 
foo

3.2.53(1)-release

$ /usr/local/bin/bash foo.sh 
foo
bar
4.3.33(1)-release

为什么这只适用于一个版本?是错误还是添加的功能?

进程替换似乎工作正常,但是在获取文件时出现问题。

如果这是预期的行为,我应该使用什么其他语法来代替 source 来自标准输入的内容以在不同的 bash 版本之间兼容?

这是一个known limitation in bash 3.2。要解决它:

source /dev/stdin <<<"$(echo bar=bar)"

...或者,类似地:

source /dev/stdin <<<"$(cat <(...))"