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

HEREDOC require {} to print multidimensional arrays values but on a normal array it doesn't. Why?

When writing in HEREDOC and posting multidimentional array values it requires {}. On normal array no. Here an example: $array = array('normal_key', 'normal_value'); $multidim = array(array('multi0_key', 'multi0_value'), …
Perocat
  • 1,481
  • 7
  • 25
  • 48
0
votes
1 answer

\\n appears as \n in an input tags -- using htmlspecialchars() on user input

I have a simple issue -- the user fills out a form and when the form is POST'd I store the data into a HEREDOC and save that to a file that can be opened and viewed in the browser. The problem is I can't figure out how to get the user's typed text…
CFHcoder
  • 429
  • 2
  • 8
  • 25
0
votes
1 answer

Why is Ruby ignoring consecutive carriage returns in a heredoc?

I used a heredoc to make some simple sample data like: > str = < p str "abc\r\r\ndef\r\r\r\n" Note the three carriage-returns become two "\r"s and the four…
Coderer
  • 25,844
  • 28
  • 99
  • 154
0
votes
0 answers

Is there a way of predefining input when running a shell?

When using a shell script file i want to be able to prewrite the input for the configuration. how can i give the answers automatically? there are multiple questions with short answers required for example- 'Please select an option: 1, 2 or 3' and…
0
votes
1 answer

using @ error controller within heredoc

How do I use the @ error controller within heredoc? Like in a case where i want to redisplay the contents of an input form field that has not yet passed validation: I get error when I use @ within heredoc as follows: <<
okey_on
  • 2,888
  • 8
  • 28
  • 36
0
votes
1 answer

Wrong output of heredoc command

Output of the code echo << but heredoc should act…
0
votes
1 answer

Heredoc syntax pushing values into arrays

I get a syntax error when I use heredoc syntax to push values into array $theArray = array(); $theArray[] = <<
gabric
  • 1,865
  • 2
  • 21
  • 32
0
votes
1 answer

How to add single quote to heredoc javascript?

I have this heredoc code: $col_formatter = <<
Marsha
  • 167
  • 3
  • 3
  • 18
0
votes
1 answer

Global array declared inside function, but values not showing when called

I am building a menu with pricing loaded by calling array keys. Menu displays but I can't get the values to show in the price section. I loaded an associative array and am looking to call its values from inside a function. I've declared global…
0
votes
1 answer

Passing python variable to linux shell

I am running a python snippet inside a heredoc in bash script. I want to pass a string from a python variable to the shell. Perhaps set a shell variable. How can I do this ??
user1600936
  • 101
  • 1
  • 3
  • 14
0
votes
2 answers

Accessing MySQL from Ubuntu Bash

Ubuntu bash mysql script looks like that mysql -h localhost -u $MYSQLLOGIN -p$MYSQLROOTPASS -t -e ' CREATE USER $USERNAME@'localhost' IDENTIFIED BY $MYSQLPASS; create database $MYSQLDB; grant usage on *.* to $USERNAME@localhost identified by…
heron
  • 3,611
  • 25
  • 80
  • 148
0
votes
2 answers

Can groovy heredocs be internationalized?

Have some multiline strings that are presented to the user and stored as Heredocs. So rather than a 'normal' (Java) property file, a groovy-based one (see here) to be consumed by ConfigSlurper was used and works great. Sorry if this is a dumb…
JoeG
  • 7,191
  • 10
  • 60
  • 105
0
votes
1 answer

How can I preserve / maintain consecutive newlines in Ruby here-document?

I wonder how can I preserve consecutive newline characters with Ruby here-document? In my program all of them are collapsed to one newline. For example: s=<
Konstantin
  • 2,983
  • 3
  • 33
  • 55
0
votes
2 answers

bashscript Heredoc + FTP error

I try to do this #!/bin/bash ftp "$HOST"$3"/"$2"/" <
Scicare
  • 833
  • 5
  • 13
  • 26