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
1 answer

No such file or directory in Heredoc, Bash

I am deeply confused by Bash's Heredoc construct behaviour. Here is what I am doing: #!/bin/bash user="some_user" server="some_server" address="$user"@"$server" printf -v user_q '%q' "$user" function run { ssh "$address" /bin/bash…
Alex
  • 937
  • 3
  • 20
  • 44
0
votes
2 answers

How to search and replace in ksh within a heredoc variable once already set?

I don't have extensive experience in ksh and am having a rough time with a multi-line variable in a script I'm trying to revise. Basically, I'm looking to strip out the first part of the resulting output up until some "CAMP" text and keep whatever…
MattB
  • 714
  • 1
  • 8
  • 18
0
votes
1 answer

Symfony console, file paths, /dev/fd/0 trick

I have my own symfony console commands, some of which take a filename as the argument. eg. $ php app/console mycommands:doTheThing /path/to/my/file.txt I have tried using the /dev/fd/0 trick to use a string instead of a file here, however it's still…
Brian Brownton
  • 1,313
  • 14
  • 31
0
votes
2 answers

For each line in command output add to array

I am trying to do the following in a bash script: add all the device node files which don't start with /dev/sda to an array called devices. As the script will be executed on a read-only filesystem, I cannot use here documents. Here is my…
user2747949
  • 163
  • 1
  • 6
  • 13
0
votes
1 answer

How can I execute SSH command with output pagination Heredoc

I'm trying to execute commands in a heredoc block SSH session using something like this: ssh -tt user@domain << 'END' > ./file.txt some command END The command is executed and saved a portion of the output at file.txt. The problem is that the…
Michael Becerra
  • 401
  • 1
  • 3
  • 15
0
votes
1 answer

regex for catching heredoc in JavaScript

I'm having a perl script, which looks for example as follows: #/usr/bin/perl -w print 'My output: '; print <
Benjamin J.
  • 1,239
  • 1
  • 15
  • 28
0
votes
1 answer

Externalize template from heredoc

How can I externalize the template part of a "heredoc"? I have a bash script that uses a "heredoc" to write data to a file: foo=bar data=$(cat <
matsev
  • 32,104
  • 16
  • 121
  • 156
0
votes
2 answers

Ruby printing using here documents

I am completely new to Ruby. I am trying to print the type and the name of a class using a method but I am getting this syntax error I cannot figure out: Code/oop.rb:47: syntax error, unexpected end-of-input puts <
Marcus
  • 128
  • 2
  • 12
0
votes
0 answers

How to pass html codes in the values of text in a form and display it

So i've updated the codes. i'm trying to make a radio box so when yes is checked on the radio box a textbox appears using angular.js hoping it would work.
0
votes
0 answers

Multiline comment missing. at heredoc

I used ejs and heredoc to compile xml files : const ejs = require('ejs'); const heredoc = require('heredoc'); var tpl = heredoc(function(){/* ]]>
Seven
  • 549
  • 1
  • 4
  • 10
0
votes
1 answer

PHP Heredoc won't display variables in HTML - WordPress

I have written some functions in my functions.php in my theme. I have: $usrProfileHTML = <<
{$envUserProfile['eUserName']}
Milos
  • 981
  • 3
  • 16
  • 41
0
votes
1 answer

Unable to use here-document delimited by EOF within phing XML

I have some commands to be run after switching to a different user. I need to do this in a build xml file. Following is what I have done -
Sandeepan Nath
  • 9,966
  • 17
  • 86
  • 144
0
votes
1 answer

Writing a bash script from bash script. Lines without interpretation

I want to create a bash script from a bash script. The problem doing it with old echo style (example echo -e "some commands" > /path/to/file.sh) is the commands are interpreted and substituted by its values. Googling I found this solution on this…
OscarAkaElvis
  • 5,384
  • 4
  • 27
  • 51
0
votes
0 answers

PHP won't interpret heredoc string

I am using PHP '5.6.16' and it refuses to interpret that Heredoc string with exception: Parse error: syntax error, unexpected end of file in ..... on line 131 131 is the end of the file. Without the heredoc string all interprets well. $data =…
Henry Lynx
  • 1,099
  • 1
  • 19
  • 41
0
votes
2 answers

is heredoc a good way to implement mvc?

Is Heredoc in MVC a good way to begin my foray into separating layers? I read one place it could be use and another that heredoc had more problems than it solved.
johnny
  • 19,272
  • 52
  • 157
  • 259