Cannot use process substitution in bash

54 views Asked by At

I have a bash script (source) which must redirect openssl output to another bash script:

stdbuf -i0 -o0 \
  openssl s_client \
    -starttls xmpp \
    -xmpphost "$domain" \
    -connect "$host:$port" \
    -quiet \
    < "$pipename" \
  | (printf '%s %s\n' "$jid" "$authstr"; \
     stdbuf -o0 tr '>\n' '\n\001') \
  | stdbuf -o0 tee "$debug_recv" \
  | stdbuf -o0 "$thisdir/echoz.sed" \
  | stdbuf -o0 tee "$debug_sent" \
  | stdbuf -o0 tr -d '\n' \
  | stdbuf -o0 tr '\001' '\n' \
  | tee >( bash commandparser.sh >> /dev/pts/0 ) \
  > "$pipename"

But it gives an error: ./echoz.sh: 38: Syntax error: "(" unexpected

If i do just the same in command line it works fine:

$ echo "[DATA]" | tee >( bash commandparser.sh >> /dev/pts/0 )
------------------NEW MESSAGE-----------------
From: 
To: 
Type: 
Text: 
------------------NEW MESSAGE-----------------\n\n
2

There are 2 answers

0
Ed Morton On BEST ANSWER

Your script starts with #!/bin/sh and sh is not necessarily bash. If you want your script to run with bash then use #!/usr/bin/env bash.

2
Paul Hodges On

Run it through ShellCheck.net.

Line 30:
    < "$pipename" \
      ^-- SC2094 (info): Make sure not to read and write the same file in the same pipeline.
 
Line 38:
    > "$pipename"
      ^-- SC2094 (info): Make sure not to read and write the same file in the same pipeline.

Your problem might be just as Ed said though - sh might be bash under the hood - my Git Bash emulation's sh allows >(...) constructs, but other versions may not, so I'd use explicitly use bash, or check to confirm your target system's sh can handle all those features.

I'd also try very hard to reduce the noise of that script...