heredoc

What's the difference between “here string” and echo + pipe

独自空忆成欢 提交于 2019-12-03 20:03:24
问题 Wondering what is the right use of here-string (here-document) and pipe. For example, a='a,b,c,d' echo $a | IFS=',' read -ra x IFS=',' read -ra x <<< $a Both methods work. Then what would be the difference between the two functionality? Another problem that I have about "read" is that: IFS=',' read x1 x2 x3 x4 <<< $a does not work, x1 is valued as "a b c d", and x2, x3, x4 has no value but if: IFS=',' read x1 x2 x3 x4 <<< "$a" I can get x1=a, x2=b, x3=c, x4=d Everything is okay! Can anyone

Formatting an array value inside a Heredoc

浪尽此生 提交于 2019-12-03 10:07:18
I was wondering why I can't do something like {number_format($row['my_number'])} inside a Heredoc. Is there any way around this without having to resort to defining a variable like $myNumber below? Looked at http://www.php.net/manual/en/language.types.string.php#language.types.string.syntax.nowdoc but found nothing. CODE foreach ($dbh -> query($sql) as $row): $myNumber = number_format($row['my_number']); $table .= <<<EOT <tr> <td>{$row['my_number']}</td> // WORKS <td>$myNumber</td> // WORKS <td>{number_format($row['my_number'])}</td> // DOES NOT WORK! </tr> EOT; endforeach; You can execute

How to pipe a here-document through a command and capture the result into a variable?

时光怂恿深爱的人放手 提交于 2019-12-02 22:51:40
Right now this outputs the value I need on stdout. How can I capture it into a variable so I can use it in the rest of the script? Requirements: The script needs to be all in one file. I'd prefer not to write any temp files, if possible. . #!/bin/bash cat << EOF | xsltproc - ../pom.xml | tail -1 <?xml version="1.0"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="/"><xsl:value-of select="/project/version"/></xsl:template> </xsl:stylesheet> EOF This seems to work (based on Ignacio's answer). By using a subshell the here-document is correctly

heredoc with eval code execution

别来无恙 提交于 2019-12-02 22:31:34
问题 I've tryed a couple of methods to try and get this working but with no luck! I've got a page like this (Example): <?php $jj = <<<END ?> <h1>blah blah</h1> <p> blah blah blah blah blah blah blah <?php include("file.php"); ?> blah blah</p> <?php END; eval('?>'.$jj.'<?php '); ?> this causes no output what so ever, can not think of a solution! 回答1: This will not work because eval only expects PHP code (i.e. not surrounded by <?php ?> tags), so the call to eval() will probably fail with a parse

Indenting heredocs with spaces [duplicate]

China☆狼群 提交于 2019-12-02 20:13:14
This question already has answers here : here-document gives 'unexpected end of file' error (5 answers) For personal development and projects I work on, we use four spaces instead of tabs. However, I need to use a heredoc, and I can't do so without breaking the indention flow. The only working way to do this I can think of would be this: usage() { cat << ' EOF' | sed -e 's/^ //'; Hello, this is a cool program. This should get unindented. This code should stay indented: something() { echo It works, yo!; } That's all. EOF } Is there a better way to do this? Let me know if this belongs on the

Have trouble when using heredoc syntax in PHP [closed]

ε祈祈猫儿з 提交于 2019-12-02 19:19:14
问题 This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center. Closed 6 years ago . <?php $output = <<< END <table style="display: table;" class="listview rowstyle-rowhighlight" id="resourcegrid"> <thead> <tr> <th width="70"></th> <th

Have trouble when using heredoc syntax in PHP [closed]

谁说我不能喝 提交于 2019-12-02 10:39:46
<?php $output = <<< END <table style="display: table;" class="listview rowstyle-rowhighlight" id="resourcegrid"> <thead> <tr> <th width="70"></th> <th style="-moz-user-select: none;" class="sortable fd-column-0"><a class="fdTableSortTrigger" href="#">Name</a></th> <th style="-moz-user-select: none;" class="sortable fd-column-1"><a class="fdTableSortTrigger" href="#">Contributor</a></th> <th style="-moz-user-select: none;" class="sortable fd-column-3"><a class="fdTableSortTrigger" href="#">Modified</a></th> </tr> </thead><tbody> END; echo $output; When I run it reports : Parse error: parse

heredoc with eval code execution

Deadly 提交于 2019-12-02 08:16:51
I've tryed a couple of methods to try and get this working but with no luck! I've got a page like this (Example): <?php $jj = <<<END ?> <h1>blah blah</h1> <p> blah blah blah blah blah blah blah <?php include("file.php"); ?> blah blah</p> <?php END; eval('?>'.$jj.'<?php '); ?> this causes no output what so ever, can not think of a solution! This will not work because eval only expects PHP code (i.e. not surrounded by <?php ?> tags), so the call to eval() will probably fail with a parse error. I would suggest using output buffering instead, for example: <?php //start output buffering, anything

How to insert a python program into a bash script?

a 夏天 提交于 2019-12-02 05:00:48
问题 I have a small python program that parses a text file and writes the output to another file. Currently, I am writing a bash script to call this program several times, it looks something like: for i in $(seq 1 100); do python /home/Documents/myProgram.py myTextFile$i done This works fine but I want to know if it is possible to have the python program inside the bash script file so when another user runs the script they don't need to have the python program in their memory; i.e., is it possible

What does <<DESC mean in ruby?

谁说胖子不能爱 提交于 2019-12-02 03:32:22
问题 I am learning Ruby, and in the book I use, there is an example code like this #... restaurant = Restaurant.new restaurant.name = "Mediterrano" restaurant.description = <<DESC One of the best Italian restaurants in the Kings Cross area, Mediterraneo will never leave you disappointed DESC #... Can someone explain to me what <<DESC means in the above example? How does it differ from the common string double quote? 回答1: It is used to create multiline strings. Basically, '<< DESC' tells ruby to