{"id":227812,"date":"2025-02-20T12:50:56","date_gmt":"2025-02-20T11:50:56","guid":{"rendered":"https:\/\/glosarix.com\/glossary\/heredoc-en\/"},"modified":"2025-02-20T12:50:56","modified_gmt":"2025-02-20T11:50:56","slug":"heredoc-en","status":"publish","type":"glossary","link":"https:\/\/glosarix.com\/en\/glossary\/heredoc-en\/","title":{"rendered":"Heredoc"},"content":{"rendered":"<p>Description: Heredoc is a technique used in programming languages and scripting environments to define multi-line text strings in a simple and readable way. Its name comes from the combination of &#8216;here&#8217; and &#8216;document&#8217;, indicating that the text is defined &#8216;here&#8217; in the code. This way of defining strings allows for the inclusion of line breaks and special characters without the need to concatenate multiple lines or use escape characters, making the code easier to write and read. In many languages, a specific delimiter followed by an identifier marks the beginning of the string, with the same identifier on a separate line indicating its end. In the context of shell scripting, the use of heredoc allows for clearer and more organized scripts, especially when working with commands that require multiple lines of text. This feature is particularly useful for generating configuration files, email messages, or any other type of output that requires a specific and readable format.<\/p>\n<p>History: The concept of heredoc became popular in the 1980s with the development of programming languages like Perl, which introduced this technique to facilitate string manipulation. Various languages adopted this feature, allowing developers to write cleaner and more readable code. Over the years, the use of heredoc has spread to other programming and scripting languages, establishing itself as an essential tool for creating scripts and programs that require the management of multi-line text.<\/p>\n<p>Uses: Heredoc is primarily used in the creation of scripts and programs that require the manipulation of multi-line text. It is common to use heredoc to define strings that contain HTML, SQL, or any other type of text that needs a specific format. In shell scripting, heredoc is used to pass multiple lines of text to commands like &#8216;cat&#8217;, &#8216;echo&#8217;, or to create configuration files in a more readable manner.<\/p>\n<p>Examples: An example of using heredoc in Ruby would be: <\/p>\n<p>&#8220;`ruby<br \/>\nhtml = <<HTML\n\n\n<h1>Title<\/h1>\n<p>This is a paragraph.<\/p>\n<p>HTML<br \/>\n&#8220;`<\/p>\n<p>In shell scripting, an example would be:<\/p>\n<p>&#8220;`bash<br \/>\necho <<EOF\nThis is a multi-line text.\nIt can contain several lines.\nEOF\n```\n<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Description: Heredoc is a technique used in programming languages and scripting environments to define multi-line text strings in a simple and readable way. Its name comes from the combination of &#8216;here&#8217; and &#8216;document&#8217;, indicating that the text is defined &#8216;here&#8217; in the code. This way of defining strings allows for the inclusion of line breaks [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"menu_order":0,"comment_status":"open","ping_status":"open","template":"","meta":{"footnotes":""},"glossary-categories":[12062,11460],"glossary-tags":[13018,12416],"glossary-languages":[],"class_list":["post-227812","glossary","type-glossary","status-publish","hentry","glossary-categories-ruby-en","glossary-categories-shell-scripting-en","glossary-tags-ruby-en","glossary-tags-shell-scripting-en"],"post_title":"Heredoc ","post_content":"Description: Heredoc is a technique used in programming languages and scripting environments to define multi-line text strings in a simple and readable way. Its name comes from the combination of 'here' and 'document', indicating that the text is defined 'here' in the code. This way of defining strings allows for the inclusion of line breaks and special characters without the need to concatenate multiple lines or use escape characters, making the code easier to write and read. In many languages, a specific delimiter followed by an identifier marks the beginning of the string, with the same identifier on a separate line indicating its end. In the context of shell scripting, the use of heredoc allows for clearer and more organized scripts, especially when working with commands that require multiple lines of text. This feature is particularly useful for generating configuration files, email messages, or any other type of output that requires a specific and readable format.\n\nHistory: The concept of heredoc became popular in the 1980s with the development of programming languages like Perl, which introduced this technique to facilitate string manipulation. Various languages adopted this feature, allowing developers to write cleaner and more readable code. Over the years, the use of heredoc has spread to other programming and scripting languages, establishing itself as an essential tool for creating scripts and programs that require the management of multi-line text.\n\nUses: Heredoc is primarily used in the creation of scripts and programs that require the manipulation of multi-line text. It is common to use heredoc to define strings that contain HTML, SQL, or any other type of text that needs a specific format. In shell scripting, heredoc is used to pass multiple lines of text to commands like 'cat', 'echo', or to create configuration files in a more readable manner.\n\nExamples: An example of using heredoc in Ruby would be: \n\n```ruby\nhtml = <<HTML\n<h1>Title<\/h1>\n<p>This is a paragraph.<\/p>\nHTML\n```\n\nIn shell scripting, an example would be:\n\n```bash\necho <<EOF\nThis is a multi-line text.\nIt can contain several lines.\nEOF\n```","yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v25.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Heredoc - Glosarix<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/glosarix.com\/en\/glossary\/heredoc-en\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Heredoc - Glosarix\" \/>\n<meta property=\"og:description\" content=\"Description: Heredoc is a technique used in programming languages and scripting environments to define multi-line text strings in a simple and readable way. Its name comes from the combination of &#8216;here&#8217; and &#8216;document&#8217;, indicating that the text is defined &#8216;here&#8217; in the code. This way of defining strings allows for the inclusion of line breaks [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/glosarix.com\/en\/glossary\/heredoc-en\/\" \/>\n<meta property=\"og:site_name\" content=\"Glosarix\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:site\" content=\"@GlosarixOficial\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/glosarix.com\/en\/glossary\/heredoc-en\/\",\"url\":\"https:\/\/glosarix.com\/en\/glossary\/heredoc-en\/\",\"name\":\"Heredoc - Glosarix\",\"isPartOf\":{\"@id\":\"https:\/\/glosarix.com\/en\/#website\"},\"datePublished\":\"2025-02-20T11:50:56+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/glosarix.com\/en\/glossary\/heredoc-en\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/glosarix.com\/en\/glossary\/heredoc-en\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/glosarix.com\/en\/glossary\/heredoc-en\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Portada\",\"item\":\"https:\/\/glosarix.com\/en\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Heredoc\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/glosarix.com\/en\/#website\",\"url\":\"https:\/\/glosarix.com\/en\/\",\"name\":\"Glosarix\",\"description\":\"T\u00e9rminos tecnol\u00f3gicos - Glosarix\",\"publisher\":{\"@id\":\"https:\/\/glosarix.com\/en\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/glosarix.com\/en\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/glosarix.com\/en\/#organization\",\"name\":\"Glosarix\",\"url\":\"https:\/\/glosarix.com\/en\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/glosarix.com\/en\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/glosarix.com\/wp-content\/uploads\/2025\/04\/Glosarix-logo-192x192-1.png.webp\",\"contentUrl\":\"https:\/\/glosarix.com\/wp-content\/uploads\/2025\/04\/Glosarix-logo-192x192-1.png.webp\",\"width\":192,\"height\":192,\"caption\":\"Glosarix\"},\"image\":{\"@id\":\"https:\/\/glosarix.com\/en\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/x.com\/GlosarixOficial\",\"https:\/\/www.instagram.com\/glosarixoficial\/\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Heredoc - Glosarix","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/glosarix.com\/en\/glossary\/heredoc-en\/","og_locale":"en_US","og_type":"article","og_title":"Heredoc - Glosarix","og_description":"Description: Heredoc is a technique used in programming languages and scripting environments to define multi-line text strings in a simple and readable way. Its name comes from the combination of &#8216;here&#8217; and &#8216;document&#8217;, indicating that the text is defined &#8216;here&#8217; in the code. This way of defining strings allows for the inclusion of line breaks [&hellip;]","og_url":"https:\/\/glosarix.com\/en\/glossary\/heredoc-en\/","og_site_name":"Glosarix","twitter_card":"summary_large_image","twitter_site":"@GlosarixOficial","twitter_misc":{"Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/glosarix.com\/en\/glossary\/heredoc-en\/","url":"https:\/\/glosarix.com\/en\/glossary\/heredoc-en\/","name":"Heredoc - Glosarix","isPartOf":{"@id":"https:\/\/glosarix.com\/en\/#website"},"datePublished":"2025-02-20T11:50:56+00:00","breadcrumb":{"@id":"https:\/\/glosarix.com\/en\/glossary\/heredoc-en\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/glosarix.com\/en\/glossary\/heredoc-en\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/glosarix.com\/en\/glossary\/heredoc-en\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Portada","item":"https:\/\/glosarix.com\/en\/"},{"@type":"ListItem","position":2,"name":"Heredoc"}]},{"@type":"WebSite","@id":"https:\/\/glosarix.com\/en\/#website","url":"https:\/\/glosarix.com\/en\/","name":"Glosarix","description":"T\u00e9rminos tecnol\u00f3gicos - Glosarix","publisher":{"@id":"https:\/\/glosarix.com\/en\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/glosarix.com\/en\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/glosarix.com\/en\/#organization","name":"Glosarix","url":"https:\/\/glosarix.com\/en\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/glosarix.com\/en\/#\/schema\/logo\/image\/","url":"https:\/\/glosarix.com\/wp-content\/uploads\/2025\/04\/Glosarix-logo-192x192-1.png.webp","contentUrl":"https:\/\/glosarix.com\/wp-content\/uploads\/2025\/04\/Glosarix-logo-192x192-1.png.webp","width":192,"height":192,"caption":"Glosarix"},"image":{"@id":"https:\/\/glosarix.com\/en\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/x.com\/GlosarixOficial","https:\/\/www.instagram.com\/glosarixoficial\/"]}]}},"_links":{"self":[{"href":"https:\/\/glosarix.com\/en\/wp-json\/wp\/v2\/glossary\/227812","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/glosarix.com\/en\/wp-json\/wp\/v2\/glossary"}],"about":[{"href":"https:\/\/glosarix.com\/en\/wp-json\/wp\/v2\/types\/glossary"}],"author":[{"embeddable":true,"href":"https:\/\/glosarix.com\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/glosarix.com\/en\/wp-json\/wp\/v2\/comments?post=227812"}],"version-history":[{"count":0,"href":"https:\/\/glosarix.com\/en\/wp-json\/wp\/v2\/glossary\/227812\/revisions"}],"wp:attachment":[{"href":"https:\/\/glosarix.com\/en\/wp-json\/wp\/v2\/media?parent=227812"}],"wp:term":[{"taxonomy":"glossary-categories","embeddable":true,"href":"https:\/\/glosarix.com\/en\/wp-json\/wp\/v2\/glossary-categories?post=227812"},{"taxonomy":"glossary-tags","embeddable":true,"href":"https:\/\/glosarix.com\/en\/wp-json\/wp\/v2\/glossary-tags?post=227812"},{"taxonomy":"glossary-languages","embeddable":true,"href":"https:\/\/glosarix.com\/en\/wp-json\/wp\/v2\/glossary-languages?post=227812"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}