linuxshellcurlgoogle-http-client

What does <<$$$ mean in a Unix shell?


I'm using the google-http-client for a project at work and when I do some requests I have the following thing printed on my console.

curl -v --compressed -X POST -H 'Accept-Encoding: gzip' -H 'User-Agent: Google-HTTP-Java-Client/1.23.0 (gzip)' -H 'Content-Type: application/x-www-form-urlencoded; charset=UTF-8' -d '@-' -- 'http://example.com' << $$$

I was wondering what << $$$ mean.

If I try to run this command into a linux terminal seems that << $$$ makes the console to wait for more input. If that's the case, how can I specify to the terminal that I'm done feeding inputs to it?

Later edit: I have found that curl arguments -d @- implies that data will be red from the stdin.


Solution

  • This is a "here-document" with an unusual end marker.

    A here-document is a type of redirection, and usually looks like

    utility <<MARKER
    document
    content
    goes here
    MARKER
    

    That is, it feeds a document delimited by MARKER to the utility on its standard input.

    This is like utility <file where file contains the lines in the here-document, except that the shell will do variable expansion and command substitution on the text of the document (this may be prevented by quoting the marker as either \MARKER or 'MARKER' at the start).

    The here-document marker can be any word, but $$$ is a highly unusual choice of word for it. As $ has a special meaning in the shell, using $ in the marker is, or may be, confusing to the reader.

    If you type

    somecommand <<stuff
    

    in the shell, the shell expects you to give the rest of the contents of the here-document, and then the word stuff on a line by itself. That's how you signal end of input in a here-document.