Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 613
kenorb Avatar asked Sep 15 '15 21:09

kenorb


1 Answers

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 <(...))"
like image 152
Charles Duffy Avatar answered Oct 02 '22 19:10

Charles Duffy