heredoc

bash run script from here doc [duplicate]

ⅰ亾dé卋堺 提交于 2019-12-20 06:27:06
问题 This question already has answers here : Using variables inside a bash heredoc (3 answers) Closed 9 months ago . In the code below, variable X is output normally. # cat a.sh X=world echo 'hello' $X # cat a.sh | bash hello world But, using here doc, variable X is not displayed. # cat <<EOF | bash > X=world > echo 'hello' $X > EOF hello # bash -s <<EOF > X=world > echo 'hello' $X > EOF hello What made this difference? 回答1: You can see what happens when you remove the |bash X=oldvalue cat <<EOF

Help me understand this Perl statement with <<'ESQ'

隐身守侯 提交于 2019-12-20 02:51:30
问题 substr($obj_strptime,index($strptime,"sub")+6,0) = <<'ESQ'; shift; # package .... .... ESQ What is this ESQ and what is it doing here? Please help me understand these statements. 回答1: It marks the end of a here-doc section. EOF is more traditional than ESQ though. 回答2: This construct is known as a here-doc (because you're getting standard input from a document here rather than an external document on the file system somewhere). It basically reads everything from the next line up to but

What is <<<_END?

这一生的挚爱 提交于 2019-12-18 19:22:15
问题 I'm new to PHP and don't understand what the point of <<<_END is. Could someone please explain when this should be used? I've looked at various examples and they all seem to have HTML embedded within them. But I can use HTML without the <<<_END tags, so why should I use them? I tried searching the manual, but I keep finding the end() method for arrays. 回答1: It's the start of a heredoc. you can do: $data = <<< _END You can write anything you want in between the start and end _END; _END can be

What is <<<_END?

核能气质少年 提交于 2019-12-18 19:18:55
问题 I'm new to PHP and don't understand what the point of <<<_END is. Could someone please explain when this should be used? I've looked at various examples and they all seem to have HTML embedded within them. But I can use HTML without the <<<_END tags, so why should I use them? I tried searching the manual, but I keep finding the end() method for arrays. 回答1: It's the start of a heredoc. you can do: $data = <<< _END You can write anything you want in between the start and end _END; _END can be

Is there heredoc alternative in Java (heredoc as PHP)? [duplicate]

♀尐吖头ヾ 提交于 2019-12-18 19:07:04
问题 This question already has answers here : Java multiline string (40 answers) Closed 4 years ago . For JAVA development I need writing to a files with strings like "\r\t\n <>", because from Java I want writing a PHP file. If you can't understand look at this example: BufferedWriter buffW = new BufferedWriter(fileW); buffW.write("<?php\n\n\tclass MyClass {\n\tpublic function test()\n}\n}\n?>"); This is mess a code, I want to write a clean such as PHP can do, but can't find on Java alternative

Working with long strings (heredocs) in Java - the readable approach? [duplicate]

一世执手 提交于 2019-12-18 15:54:15
问题 This question already has answers here : Java multiline string (40 answers) Closed 4 years ago . I need to work with long strings containing line breaks in Java. Those are for HTML generation, but it is not the most important here. I'm aware Java is cripple in a way it doesn't have heredocs . But there are other mechanisms I could use: 1) String concatenation (or StringBuilders), not very readable and copy-pasteable. 2) Storing strings in .properties files, either not very readable, but with

/dev/stdin with herestring

限于喜欢 提交于 2019-12-18 04:55:08
问题 I would like a Bash script that can take input from a file or stdin, much like grep , for example $ cat hw.txt Hello world $ grep wor hw.txt Hello world $ echo 'Hello world' | grep wor Hello world $ grep wor <<< 'Hello world' Hello world all works beautifully. However with the following script read b < "${1-/dev/stdin}" echo $b It fails if using a herestring $ hw.sh hw.txt Hello world $ echo 'Hello world' | hw.sh Hello world $ hw.sh <<< 'Hello world' /opt/a/hw.sh: line 1: /dev/stdin: No such

Dirt-simple PHP templates… can this work without `eval`?

喜夏-厌秋 提交于 2019-12-17 10:42:34
问题 Update- Thanks for all the responses. This Q is getting kind of messy, so I started a sequel if anyone's interested. I was throwing together a quick script for a friend and stumbled across a really simple way of doing templating in PHP. Basically, the idea is to parse the html document as a heredoc string, so variables inside of it will be expanded by PHP. A passthrough function allows for expression evaluation and function and static method calls within the string: function passthrough($s)

HEREDOC Returning unexpected end

一曲冷凌霜 提交于 2019-12-17 10:04:13
问题 The following snippet is causing an "PHP Parse error: syntax error, unexpected $end in /Applications/MAMP/htdocs3/nettuts/PHP/PDO for Database Access/htdocs/view_users02.php on line 39" I've looked around the site and google but didn't find an exact solution. foreach($DBH->query($sql) as $row){ $output = "<tr><td align='left'>" . $row["name"] . "</td><td align='left'>" . $row["dr"] . "</td></tr>"; // echo '<tr><td align="left">' . $row['name'] . '</td><td align="left">' . $row['dr'] . '</td><

Executing multi-line statements in the one-line command-line?

爷,独闯天下 提交于 2019-12-16 22:35:16
问题 I'm using Python with -c to execute a one-liner loop, i.e.: $ python -c "for r in range(10): print 'rob'" This works fine. However, if I import a module before the for loop, I get a syntax error: $ python -c "import sys; for r in range(10): print 'rob'" File "<string>", line 1 import sys; for r in range(10): print 'rob' ^ SyntaxError: invalid syntax Any idea how this can be fixed? It's important to me to have this as a one-liner so that I can include it in a Makefile. 回答1: you could do echo