标签: heredoc

如何通过命令管理here-document并将结果捕获到变量中?

现在,这将输出我在stdout上需要的值.如何将其捕获到变量中,以便我可以在脚本的其余部分中使用它?

要求:

  • 该脚本需要全部在一个文件中.
  • 如果可能的话,我宁愿不写任何临时文件.

.

#!/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
Run Code Online (Sandbox Code Playgroud)

bash shell heredoc

16
推荐指数
2
解决办法
2万
查看次数

Java中是否有heredoc替代品(heredoc作为PHP)?

对于JAVA开发,我需要写一个包含"\ r\t \n <>"字符串的文件,因为从Java我想编写一个PHP文件.如果您无法理解,请查看此示例:

BufferedWriter buffW = new BufferedWriter(fileW);
            buffW.write("<?php\n\n\tclass MyClass {\n\tpublic function test()\n}\n}\n?>");
Run Code Online (Sandbox Code Playgroud)

这是一个乱码的代码,我想写一个干净的如PHP可以做的,但是在Java替代方式上找不到例如:

 <?php
$mystring = <<<EOT
    This is some PHP text.
    It is completely free
    I can use "double quotes"
    and 'single quotes',
    plus $variables too, which will
    be properly converted to their values,
    you can even type EOT, as long as it
    is not alone on a line, like this:
EOT;
?> 
Run Code Online (Sandbox Code Playgroud)

php java heredoc readfile

15
推荐指数
1
解决办法
1万
查看次数

管道这里记录命令到日志文件

通常我会使用以下构造将输出管道输出到日志文件,同时保持输出也在显示器上

./command 2>&1 | tee output.log
Run Code Online (Sandbox Code Playgroud)

我正在尝试做类似的事情,但使用这里的文档:

./command << HEREDOC
params
HEREDOC 2>&1 | tee output.log
Run Code Online (Sandbox Code Playgroud)

这不起作用 - 是否有可能实现这一目标?

bash heredoc

14
推荐指数
1
解决办法
2524
查看次数

Heredoc不工作

<?php

$information = <<<INFO 
Name: John Smith
Address: 123 Main St
City: Springville, CA
INFO;

echo $information;

?>
Run Code Online (Sandbox Code Playgroud)

结果:

解析错误:语法错误,第3行意外的T_SL

php heredoc

13
推荐指数
2
解决办法
1万
查看次数

JavaScript多行字符串

问题是:

什么是将多行字符串存储到变量中的JavaScript方法,就像在PHP中一样?

javascript string heredoc multiline

13
推荐指数
4
解决办法
1万
查看次数

我可以在bash中读取heredoc的行吗?

这就是我正在尝试的.我想要的是最后echo说"一二三四测试......",因为它循环.它不起作用; read line即将到来.这里有一些微妙的东西,或者这不起作用?

array=( one two three )
echo ${array[@]}
#one two three
array=( ${array[@]} four )
echo ${array[@]}
#one two three four


while read line; do
        array=( ${array[@]} $line )
        echo ${array[@]}
done < <( echo <<EOM
test1
test2
test3
test4
EOM
)
Run Code Online (Sandbox Code Playgroud)

bash heredoc

11
推荐指数
2
解决办法
1万
查看次数

什么是<<< _ END?

我是PHP的新手,并不明白其重点<<<_END.有人可以解释什么时候应该使用它吗?我查看了各种示例,它们似乎都嵌入了HTML.但我可以在没有<<<_END标签的情况下使用HTML ,那么我为什么要使用它们呢?我试着搜索手册,但我一直在寻找end()阵列的方法.

php heredoc

11
推荐指数
1
解决办法
2万
查看次数

PyCharm自动完成,类型列表

如何我可以告诉DocstringPyCharm返回类型列表中SomeClass的实例?

试过:@rtype [SomeClass]但它只是作为list.

python casting autocomplete heredoc pycharm

11
推荐指数
1
解决办法
1946
查看次数

在C++中,当cin是bash heredoc时调用fork会导致重复的输入片段

我正在用C++实现类似shell的程序.它有一个从cin,forks读取并等待孩子的循环.

如果输入是交互式的,或者如果它是从另一个程序传送的,那么这种方法很好.但是,当输入是bash heredoc时,程序会重新读取部分输入(有时是无限期).

我知道子进程继承了父进程的文件描述符,包括共享文件偏移量.但是,这个例子中的孩子没有从cin读取任何东西,所以我认为它不应该触及偏移量.我有点难过为什么会这样.


TEST.CPP:

#include <iostream>
#include <unistd.h>
#include <sys/wait.h>

int main(int argc, char **argv)
{
    std::string line;
    while (std::getline(std::cin, line)) {
        pid_t pid = fork();
        if (pid == 0) { // child
            break; // exit immediately
        }
        else if (pid > 0) { // parent
            waitpid(pid, nullptr, 0);
        }
        else { // error
            perror("fork");
        }

        std::cout << getpid() << ": " << line << "\n";
    }
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

我编译如下:

g++ test.cpp -std=c++11
Run Code Online (Sandbox Code Playgroud)

然后我运行它:

./a.out <<EOF …
Run Code Online (Sandbox Code Playgroud)

c++ bash fork heredoc istream

11
推荐指数
1
解决办法
282
查看次数

是否有可能在PHP中连接heredoc字符串..?

使用普通的PHP字符串,您可以这样做:

$str = "Hello ";
$str .= "world";
$str .= "bla bla bla";
$str .= "bla bla bla...";
Run Code Online (Sandbox Code Playgroud)

但你可以用heredoc字符串做同样的事情吗?

$str = <<<EOD
Hello 
world
EOD;

$str .= <<<EOD
bla bla bla";
bla bla bla...";
EOD;
Run Code Online (Sandbox Code Playgroud)

php string heredoc string-concatenation

10
推荐指数
3
解决办法
6902
查看次数