shell 无法在bash中使用进程替换

v6ylcynt  于 2023-04-12  发布在  Shell
关注(0)|答案(2)|浏览(138)

我有一个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
kyvafyod

kyvafyod1#

Your script#!/bin/sh开头,并且sh不一定是bash。如果希望脚本以bash运行,则使用#!/usr/bin/env bash

z6psavjg

z6psavjg2#

通过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.

你的问题可能就像艾德说的那样-sh * 可能 * 是bash-我的Git Bash模拟器的sh允许>(...)结构,但其他版本可能不允许,所以我会显式使用bash,或者检查以确认目标系统的sh可以处理所有这些功能。
我也会努力减少剧本中的“噪音”。

相关问题