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
2 answers

PHP functions inside HEREDOC - returned to a tab layout

I have a php function that dynamically queries a database, and returns 6 tables. I want to store each of these tables as a php array element, pass the array back via JSON/AJAX, and display each table as a seperate on a page. I wrote test code to do…
Damoven
  • 5
  • 1
0
votes
3 answers

How to suppress comments in linux ssh here script

When using here script in a linux bash to run commands on a remote server all the lines are printed. How can the comments be suppressed? The output of the below code should be: ls ... (whatever is in this folder) echo -e this is a test\ndone this…
hogan
  • 1,434
  • 1
  • 15
  • 32
0
votes
1 answer

cat in multiple ssh commands does not work

This is probably very basic but unfortunately I have no idea how to google it. Why doesn't the snippet below work as expected? I mean, how can I make cat point to the remote file? #!/bin/bash ssh user@remoteaddress << EOF mkdir sandpit cd…
akai
  • 2,498
  • 4
  • 24
  • 46
0
votes
3 answers

Heredoc while loop, decrementing by 2 instead of 1

My while loop is decrementing by two and I cannot find the cause. I feel that I do not understand how PHP is interacting with the HTML.Any words of clarity? (Note the index of the dictionaries start at 1) if (isset($title)) { $i =…
kyledewy
  • 3
  • 3
0
votes
1 answer

How to duplicate an html file with a single number in each file incremented?

I have a basic 10 line html file, but I need to duplicate the file 300 times. In the file there is a number that I need to increment by 1 so that the first file contains a "1" and the last file contains a "300." For obvious reasons I don't want to…
Charles Watson
  • 1,065
  • 2
  • 16
  • 39
0
votes
1 answer

ssh + here-document syntax with Python

I'm trying to run a set of commands through ssh from a Python script. I came upon the here-document concept and thought: cool, let me implement something like this: command = ( ( 'ssh user@host /usr/bin/bash <
user2186862
  • 213
  • 2
  • 8
0
votes
3 answers

Bash - how to replace a single line starting with a pattern with multiple lines defined in a variable?

I have a file that at some point contains a line like the following: VIRTUAL_ENV="/afs/sern.ch/user/l/lronhubbard/virtual_environment" It is the sole line in the file that begins with VIRTUAL_ENV. Using a script, I want to replace this line with…
d3pd
  • 7,935
  • 24
  • 76
  • 127
0
votes
2 answers

Bash variable is always empty

The result of the following bash script is "empty line" in output ssh dev@my_service <
Sb Lon
  • 111
  • 2
  • 6
0
votes
2 answers

How to include foreach statement inside heredoc EOM

I use EOM inside laravel controller to write html code and then pass it to a PDF class called TCPDF, the reason I'm doing this is because TCPDF doesn't load views, that's why I have to write html and css inside my controller. Everything worked fine…
Sam Joni
  • 159
  • 2
  • 14
0
votes
1 answer

How can I execute all script parameters that use here doc?

I have a simple script, which I use throughout my code base, called sshpass. #!/bin/bash expect << EOF spawn $@ expect { "*assword" { send "$SSHPASS\n" } } expect eof EOF The way I'm currently utilizing this script is like this…
self.
  • 1,612
  • 4
  • 18
  • 35
0
votes
3 answers

Escaping the close-bracket character in a bash v3 heredoc

I have a need to embed a fragment of a shell script in a heredoc as part of the creation of a cloud-init script to provision an Ubuntu 14.04 LTE machine. A simplified version of the script demonstrating the problem is as…
Graham Leggett
  • 911
  • 7
  • 20
0
votes
1 answer

Clearer alternative to "Here Documents"

When creating a file example in a bash script, you can use cat and a here document with EOF as delimiter: cat < example 1234 ABCD EFGH EOF This looks quite complicated to a bash newbie, so would there be a clearer version to write this code?
rubo77
  • 19,527
  • 31
  • 134
  • 226
0
votes
1 answer

How to make expect nested in the bash script properly?

Here is the expect file which can run succesfully. #!/usr/bin/expect -f set host vps_ip set user test set loginpwd passwd set adminpwd passwd set timeout 300 set prompt "#|>|\\\$" spawn scp /home/wpdatabase_backup.sql …
showkey
  • 482
  • 42
  • 140
  • 295
0
votes
1 answer

Parsing only some variables with heredoc or nowdoc

Using heredoc or nowdoc, how could I create $sting? $x_value=2; $string='$x='.$x_value.';'; exit($string); //$x=2; PS. I am aware of the slippery slope of script like this
user1032531
  • 24,767
  • 68
  • 217
  • 387