<<< 在 bash 中意味着什么(即在 socat ... <<<"string" >output-filename 中)

What does <<< mean in bash (ie. in socat ... <<<"string" >output-filename)

我试图理解一个代码库,我在其中看到如下一行: socat /tmp/haproxy - <<< "show servers state" > /var/state/haproxy/global

socat 在这里做什么? <<< 是什么意思?

socat 命令的 man 页面和 bash 可能有帮助(注意 <<< 是 bash 功能)

尝试:

man socat
man bash
# Type the following when the bash man page is open
# it will point you right to the explanation of <<<
/<<<  

socat 命令在文件 /tmp/haproxystdin 之间创建一个双向管道,通过将 - 传递给 socat 来表示。

实际上它将标准输入附加到 /tmp/haproxy 并将结果输出写入 /var/state/haproxy/global

<<< 是一个 bash 特征,即所谓的 here string。它将字符串 "show server state" 作为标准输入传递给 socat.

A posix shell 版本为:

echo "show servers state" | socat /tmp/haproxy - > /var/state/haproxy/global

<<< 是一种将字符串放在 stdin

上的 bashism