我有一个 bash 脚本(source),它必须将 openssl 输出重定向到另一个 bash 脚本:
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"
但是报错:
./echoz.sh: 38: Syntax error: "(" unexpected
如果我在命令行中做同样的事情,它工作正常:
$ echo "[DATA]" | tee >( bash commandparser.sh >> /dev/pts/0 )
------------------NEW MESSAGE-----------------
From:
To:
Type:
Text:
------------------NEW MESSAGE-----------------\n\n
通过 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.
您的问题可能正如 Ed 所说的那样 -
sh
might 是 bash
在引擎盖下 - 我的 Git Bash 仿真的 sh
允许 >(...)
构造,但其他版本可能不会,所以我会明确使用使用 bash
,或检查以确认您的目标系统的 sh
可以处理所有这些功能。
我也会非常努力地减少那个脚本的噪音...