读取管道程序输出时出现管道中断错误

读取管道程序输出时出现管道中断错误

我正在按照这些思路做一些事情:

declare -Ft handle_format_output &>/dev/null && exit 1   # test if this function name is already present in this scope
handle_format_output() {
    case $1 in
    domain) ./scripts/idn_to_punycode.pl >>"${2}_${1}.txt" ;;
    ipv4)
        # read doesn't bother w/ pipe input as its undefined: guessing it's leading to pipe breaks
        # therefore open stdin as a separate file and read from it to close the previous pipe
        while IFS= read -r line <&3; do
            case $line in
            */*) printf "%s\n" "$line" >>"${2}_${1}_cidr.txt" ;; # cidr block
            *-*) ipcalc "$line" >>"${2}_${1}_cidr.txt" ;;        # deaggregate ip range
            *) printf "%s\n" "$line" >>"${2}_${1}.txt" ;;        # ip address
            esac
        done 3< /dev/stdin
        ;;
    ipv6) cat -s >>"${2}_${1}.txt" ;;
    esac
}

...  |
  mawk '!seen[$0]++' | # filter duplicates and blank lines
  handle_format_output "$format" "$color"

其中输入是线性文本,可以是 Web 域、IPv4 地址、IPv4 CIDR 块或 IPv6 地址。格式为“域”、“ipv4”或“ipv6”。颜色为“白色”或“黑色”。

无论我如何尝试,都会不断抛出此错误:

mawk: write failure (Broken pipe)
mawk: close failed on file /dev/stdout (Broken pipe)
Error: Process completed with exit code 2.

我究竟做错了什么?

答案1

我想到了!一些格式数据字段是“ivp4”而不是“ipv4”。我现在想知道为什么已经成功构建了这么长时间,但是在修复它们之后,常规管道现在可以工作了。

相关内容