微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

如何解决如何在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 举报,一经查实,本站将立刻删除。