Search code examples
bashshellteeprocess-substitution

Cannot use process substitution in bash


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

Solution

  • 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.