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

限于喜欢 提交于 2019-12-11 04:26:50

问题


I am trying to understand a codebase where I see a line like below: socat /tmp/haproxy - <<< "show servers state" > /var/state/haproxy/global

What is socat doing here? What does <<< mean?


回答1:


The socat command creates a bidirectional pipe between the file /tmp/haproxy and stdin which is expressed by passing - to socat.

In fact it appends stdin to /tmp/haproxy and writes the resulting output to /var/state/haproxy/global

<<< is a bash feature, a so called here string. It passes the string "show server state" as stdin to socat.




回答2:


A posix shell version would be:

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

<<< is a bashism to put a string on stdin




回答3:


The man pages of the socat command and bash may help (Note that <<< is a bash feature)

Try:

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


来源:https://stackoverflow.com/questions/36036073/what-does-mean-in-bash-ie-in-socat-string-output-filename

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!