如何在bash的读取循环中使用进程替换?

问题描述

我想解析HAProxy状态套接字的内容,以减少噪音。我写了以下bash脚本:

#!/bin/sh

while IFS=,read -r pxname svname qcur qmax scur smax slim stot bin bout dreq dresp ereq econ eresp wretr wredis status weight act bck chkfail chkdown lastchg downtime qlimit pid iid sid throttle lbtot tracked type rate rate_lim rate_max check_status check_code check_duration hrsp_1xx hrsp_2xx hrsp_3xx hrsp_4xx hrsp_5xx hrsp_other hanafail req_rate req_rate_max req_tot cli_abrt srv_abrt comp_in comp_out comp_byp comp_rsp lastsess last_chk last_agt qtime ctime rtime ttime; do
    [[ "$pxname" != "# pxname" ]] && echo "$pxname $svname $status"
done < <(echo "show stat" | socat stdio /var/run/haproxy.sock | sort)

执行它时,出现以下错误

line 5: Syntax error near unexpected token `<'

虽然我不是bash专家,但是我对流程替换的理解是,我可以在通常可以使用文件的任何地方使用它。实际上,将<(....)替换为haproxy.csv可以正常工作。 haproxy.csvecho "show stat" | socat stdio /var/run/haproxy.sock | sort

输出

如何读取括号内命令的输出并进行循环处理?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)