heredoc

Run ES6 code in Bash terminal with Bash heredoc

心已入冬 提交于 2019-12-10 11:34:01
问题 ES5 code can be run easily with Bash heredoc in terminal: node <<HEREDOC var fs = require("fs"); ... HEREDOC But ES6 code doesn't run, even with the correct --experimental-modules flag: node --experimental-modules <<HEREDOC import fs from "fs"; ... HEREDOC The error shown is: (node:4130) ExperimentalWarning: The ESM module loader is experimental. [stdin]:1 import fs from "fs"; ^^ SyntaxError: Unexpected identifier at new Script (vm.js:83:7) at createScript (vm.js:267:10) at Proxy

What's the difference between these two Perl snippets?

非 Y 不嫁゛ 提交于 2019-12-10 03:39:38
问题 print <<EOF stuff EOF ; print <<EOF; stuff EOF Why would you use one over the other? 回答1: Those two examples amount to the same thing behaviourally, but consider if you wanted to do something else after printing that block: print <<EOF stuff EOF . "more text here"; ...or maybe you need to test the result of the operation: print $unstable_filehandle <<EOF stuff EOF or warn "That filehandle finally disappeared: $!"; These examples are contrived, but you can see how sometimes it can be useful to

Formatting an array value inside a Heredoc

不问归期 提交于 2019-12-09 07:59:10
问题 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

Defining a bunch of functions with eval (PHP)

喜你入骨 提交于 2019-12-08 09:21:21
问题 Is this anywhere near something acceptable? I need a function for each HTML tag, and they need to be defined for later use in a Heredoc string. This is my code so far. <?php $tags = array (h1, h2, h3, b, i); foreach ($tags as $key => $value) { eval ('function '.$value.' ($str) { return "<'.$value.'>$str</'.$value.'>"; }'); } This basically takes care of the Heredoc problem concerning functions within heredoc. A quick example: <<<example <h1>This is ordinary HTML</h1> {$h1('This is HTML via.

Run ES6 code in Bash terminal with Bash heredoc

前提是你 提交于 2019-12-08 08:49:30
ES5 code can be run easily with Bash heredoc in terminal: node <<HEREDOC var fs = require("fs"); ... HEREDOC But ES6 code doesn't run, even with the correct --experimental-modules flag: node --experimental-modules <<HEREDOC import fs from "fs"; ... HEREDOC The error shown is: (node:4130) ExperimentalWarning: The ESM module loader is experimental. [stdin]:1 import fs from "fs"; ^^ SyntaxError: Unexpected identifier at new Script (vm.js:83:7) at createScript (vm.js:267:10) at Proxy.runInThisContext (vm.js:319:10) at Object.<anonymous> ([stdin]-wrapper:6:22) at Module._compile (internal/modules

Loop inside “heredoc” in shell scripting

﹥>﹥吖頭↗ 提交于 2019-12-08 02:34:01
问题 I need to execute series of commands inside an interactive program/utility with parameterized values. Is there a way to loop inside heredoc ? Like below .. Not sure if eval can be of any help here. Below example doesn't seem to work as the interactive doesn't seem to recognize system commands. #!/bin/sh list="OBJECT1 OBJECT2 OBJECT3" utilityExecutable << EOF for i in $list ; do utilityCommand $i done EOF 回答1: Instead of passing a here-document to utilityExecutable , the equivalent is to pipe

Python subprocess with heredocs

旧时模样 提交于 2019-12-07 09:25:00
问题 I was playing around with Python's subprocess module, trying a few examples but I can't seem to get heredoc statements to work. Here is the trivial example I was playing with: import subprocess a = "A String of Text" p = subprocess.Popen(["cat", "<<DATA\n" + a + "\nDATA"]) I get the following error when I run the code above: cat: <<DATA\nA String of Text\nDATA: No such file or directory Am I doing it wrong? Is this even possible? If so how would I go about doing it? Update Just wanted to say

Bash tries to execute commands in heredoc

和自甴很熟 提交于 2019-12-06 06:13:31
问题 I am trying to write a simple bash script that will print a multiline output to another file. I am doing it through heredoc format: #!/bin/sh echo "Hello!" cat <<EOF > ~/Desktop/what.txt a=`echo $1 | awk -F. '{print $NF}'` b=`echo $2 | tr '[:upper:]' '[:lower:]'` EOF I was expecting to see a file in my desktop with these contents: a=`echo $1 | awk -F. '{print $NF}'` b=`echo $2 | tr '[:upper:]' '[:lower:]'` But instead, I am seeing these as the contents of my what.txt file: a= b= Somehow, even

PHP Heredoc String Rules

大城市里の小女人 提交于 2019-12-06 03:37:39
问题 Can someone here explore the intricacies of using heredoc in PHP using example php code snippets? , based on what the manual says below? php.net manual says: It is very important to note that the line with the closing identifier must contain no other characters, except possibly a semicolon ( ; ). That means especially that the identifier may not be indented, and there may not be any spaces or tabs before or after the semicolon. It's also important to realize that the first character before

Is nesting of Here Document possible in a unix bash script?

点点圈 提交于 2019-12-05 13:26:32
问题 Is it possible to write a heredoc within another heredoc ? ssh -T -q yxz@server1 <<-"END_TEXT" . . ssh -T -q abc@server2 <<-"SUB_TEXT" . . SUB_TEXT . . END_TEXT 回答1: Yes However, the nested heredoc terminator will only be recognized when indented if the indentation is done with actual tabs. Spaces won't work. So you probably want to do something more like: ssh s1 << \eof1 ssh s2 << \eof2 hostname eof2 eof1 来源: https://stackoverflow.com/questions/13254077/is-nesting-of-here-document-possible