Heredoc

Table of Contents

1. Overview

  • Definition: Heredoc (here-document) is a feature in Unix and programming languages like Bash, Perl, and Python for defining multiline string literals.
  • Syntax: A heredoc starts with << followed by a delimiter (identifier) and ends with the same delimiter on a new line.
  • Usage: Commonly used for passing blocks of text to commands, or for creating multi-line strings directly in the script.
  • Examples:
    • Bash:

      cat <<EOF
      This is a heredoc example.
      It can span multiple lines.
      EOF
      
    • Python:

      multiline_string = """This is a heredoc in Python.
      It can also span multiple lines."""
      
Tags::unix: