Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 685963
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T01:58:33+00:00 2026-05-14T01:58:33+00:00

I needed to write a script to enter multi-line input to a program (

  • 0

I needed to write a script to enter multi-line input to a program (psql).

After a bit of googling, I found the following syntax works:

cat << EOF | psql ---params
BEGIN;

`pg_dump ----something`

update table .... statement ...;

END;
EOF

This correctly constructs the multi-line string (from BEGIN; to END;, inclusive) and pipes it as an input to psql.

But I have no idea how/why it works, can some one please explain?

I’m referring mainly to cat << EOF, I know > outputs to a file, >> appends to a file, < reads input from file.

What does << exactly do?

And is there a man page for it?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T01:58:33+00:00Added an answer on May 14, 2026 at 1:58 am

    This is called heredoc format to provide a string into stdin. See https://en.wikipedia.org/wiki/Here_document#Unix_shells for more details.


    From man bash:

    Here Documents

    This type of redirection instructs the shell to read input from
    the current source until a line
    containing only word (with no trailing
    blanks) is seen.

    All of the lines read up to that point are then used as the
    standard input for a command.

    The format of here-documents is:

              <<[-]word
                      here-document
              delimiter
    

    No parameter expansion, command substitution, arithmetic expansion, or
    pathname expansion is performed on
    word. If any characters in word are
    quoted, the
    delimiter is the result of quote removal on word, and the lines
    in the here-document are not expanded.
    If word is unquoted, all lines of the
    here-document are subjected to parameter expansion, command
    substitution, and arithmetic
    expansion. In the latter case, the
    character sequence \<newline> is
    ignored, and \ must be used to quote the characters \, $, and `.

    If the redirection operator is <<-, then all leading tab characters
    are stripped from input lines and the
    line containing delimiter. This
    allows here-documents within shell scripts to be indented in a natural fashion.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have an existing java-based heavyweight project that needed an interactive script interpreter. After
I'm trying to write a bash script and I needed to do some floating
I've recently needed to write a script that performs an os.fork() to split into
Last week I started to write a script in Ruby. I needed to scrape
I don't know VBScript, but recently I needed to write a script that had
Needed to write a server text file as the output of a business process
I needed to write a custom module in drupal to help out with my
I am trying to write a VBA script which imports all of the Excel
How do you write a Maxscript that gets the three points needed to create
I want to write a vb or bat script that goes through a file

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.