Questions tagged [heredoc]

A Here-document is a special syntax of writing literal strings in sourcecode, used by different programming languages.

A heredoc or Here-Document is a way of writing literal strings in sourcecode. Many languages use heredocs: PHP, Perl, C#...

Although syntax can differ between programming languages, most heredocs start by putting a keyword, and end when the keyword is encountered as the only element on a line (no spaces, tabs or other characters are allowed). Perl example:

my $text = <<KEYWORD; #Any non-reserved word would do
This is some text.
It can contain $othervariables which will be replaced
Unless KEYWORD was between single quotes, in Perl.
KEYWORD
761 questions
0
votes
3 answers

read file in here document bash script

When I execute this, I get just empty lines as output # /bin/bash <<- EOF while read a do echo $a done < /etc/fstab EOF If I copy the content of here-document into file and execute it, everything works as expected (I get content of /etc/fstab…
facha
  • 11,862
  • 14
  • 59
  • 82
0
votes
2 answers

Syntax error unexpected $end

It's giving me unexpected $end but I can't find where is the problem, there's no spaces or indentation before or after EOD. I'm using eval() to do the replacing. {$type}())): …
0
votes
1 answer

Sublime incorrectly highlighting php heredoc blocks as syntax error

So this isn't supposed to be happening: That's a properly formatted heredoc, but it looks like Submlime sees<< tag. Does anyone else have this issue? Is there a fix?
matt lohkamp
  • 2,174
  • 3
  • 28
  • 47
0
votes
2 answers

Weird HEREDOC output order

I am using (or at least tying to) PHP HEREDOC function as a templating engine. I have implemented external caller string that can directly process external functions in HEREDOC, and that works successfully. The problem I am facing now is that the…
mrmut
  • 484
  • 5
  • 18
0
votes
3 answers

PHP HEREDOC parsing?

I am writing a CMS templating "engine". The idea is quite simple - I would preload snippets of HTML in HEREDOC strings, and than call them as and if the flow control asks for them. The issue is that heredoc strings behave strange. Here is the…
mrmut
  • 484
  • 5
  • 18
0
votes
2 answers

Heredoc string php problems

I am trying to compose an email content with heredoc. I have no idea how to access variables stored from some previous sql queries and insert them into the text. Here's the sql queries: $week=mysql_query('SELECT `Name`, `fname`, `Marca` FROM…
user3864308
  • 25
  • 1
  • 9
0
votes
2 answers

Getting parse error while retrieving details from database and also when using heredoc syntax

I have been working on a PHP project, and i am getting an error in one file i.e Parse error: syntax error, unexpected '' (T_ENCAPSED_AND_WHITESPACE), expecting identifier (T_STRING) or variable (T_VARIABLE) or number (T_NUM_STRING) in…
Mak
  • 11
0
votes
1 answer

print array elements within text body in bash

I'm writing a bash script to generate the common file: /etc/udev/rules.d/70-persistent-net.rules. You can see my function has 3 arguments and 2 of them are arrays. I'm trying to print the array elements inline within the text below (where it says…
user1527227
  • 2,068
  • 5
  • 25
  • 36
0
votes
3 answers

Does heredoc output variables which contains quotes?

I am using this: $variable = "Name is \"Bob\""; $message = << EOF; And the result is : Actually, this is synthetic example and I am working with db. But I tried: this synthetic example works (to…
Sharikov Vladislav
  • 7,049
  • 9
  • 50
  • 87
0
votes
2 answers

perl printing to stdout instead of printing to file

So I'm bangin my head against the wall on this one, and honestly think I'm missing something simple. I'm also thinking that my issue is either something wrong with the herdoc or something wrong with how I'm using STDIN. Anywho, when I run the…
Rooster
  • 9,954
  • 8
  • 44
  • 71
0
votes
2 answers

How should I be using variables in bash shell sending heredoc section over ssh?

I have a bash script that I am trying to reconfigure to remove some hardcoded values. The script sets a variable with the content from a heredoc section and that variable is passed through to the remote server via…
DaFoot
  • 1,475
  • 8
  • 29
  • 58
0
votes
1 answer

A simle Perl code with here-document works on Linux but not on Windows

While practicing I found that the following code is working fine on Linux but not on Windows print<
nikhil mehta
  • 972
  • 15
  • 30
0
votes
2 answers

svn command line: heredoc as message

Is there a way to use a heredoc as the message via the svn command? I tried this: $ echo < line one input > line two input >TEXT In my repository it just writes the dash as the message. I tried searching around and…
Chris Schmitz
  • 20,160
  • 30
  • 81
  • 137
0
votes
5 answers

How a function should exit when it called with here-document from shell script?

I have a COBOL program which should be run thru shell script and should accept the values from the here document. in the here document, i should call a function that should let control to be exit abnormally with exit code. I have tried as below but…
ANR
  • 543
  • 1
  • 4
  • 13
0
votes
1 answer

simplexml_load_string failure when using heredoc-style string parameter

I am trying one simple PHP XML example as following. // code of PHP ===================================================
Hong Wang
  • 93
  • 2
  • 11