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

微笑、不失礼 提交于 2019-11-26 06:07:52

问题


I\'ve the following shell script:

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

However it works differently in GNU bash 3.2 and 4.3 as shown below:

$ /bin/bash foo.sh 
foo

3.2.53(1)-release

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

Why this works only on one version? Is it a bug or added feature?

It seems the process substitution works fine, however problem lay when sourcing the file.

If this is expected behaviour, what other syntax should I use instead to source something from the standard input to be compatible between different bash versions?


回答1:


This is a known limitation in bash 3.2. To work around it:

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

...or, similarly:

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


来源:https://stackoverflow.com/questions/32596123/why-source-command-doesnt-work-with-process-substitution-in-bash-3-2

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