4

I am trying to use process substitution to avoid using temporary files. I tried the following:

diff <(echo "a") <(echo "b")

on mingw32/msys (from http://www.mingw.org/ as of Dec 2013), and got:

sh: syntax error near unexpected token `('

Running the same thing on Ubuntu 12.04 returns:

1c1
< a
---
> b

The msys I use probably has bash 3.1. I was wondering if it is possible to work around the issue so that the same job can be done in msys/older bash without using temporary files.

Thanks.

thor
  • 21,418
  • 31
  • 87
  • 173

1 Answers1

4

I mananed to do process substitution in bash 3.x. The syntax is correct. It is supported by bash shell. So I would suggest to check what shell your are running and execute somiting like:

/bin/bash diff <(echo "a") <(echo "b")

Process substitution is not a POSIX compliant feature. To enable try to run:

set +o posix

See also this for more info.

The other way is to use named pipes. I tested on GNU bash version 4.1.2(1):

diff - p <<< "test" & echo "test2" > p

See Working with Named Pipes

idobr
  • 1,537
  • 4
  • 15
  • 31
  • I got: $ /bin/bash diff <(echo "a") <(echo "b") sh: syntax error near unexpected token `(' – thor Jan 31 '14 at 21:52
  • uname -a: MINGW32_NT-5.2 DOCTOR 1.0.18(0.48/3/2) 2012-11-21 22:34 i686 Msys – thor Jan 31 '14 at 21:52
  • 1
    I installed msys. It still does not support process substitution. See old [post](http://stackoverflow.com/questions/3983484/does-the-current-version-of-msysgit-support-process-substitution). Try to use named pipes instead. My second example works fine. – idobr Feb 02 '14 at 20:41
  • Thanks. The second command seems to work ok. Mind explaining the line a little bit? A minor issue is the input seems to hang, and I need to hit Enter to get back the bash prompt $. – thor Feb 02 '14 at 23:40