Mar*_*ouf 16 bash shell heredoc
现在,这将输出我在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)
Mar*_*ouf 13
这似乎有效(基于Ignacio的答案).通过使用子shell,here-document被正确地传送到xsltproc,同时仍然通过尾部传递.
VERSION=$((xsltproc - ../pom.xml | tail -1) << EOF
<?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)
Ign*_*ams 12
该cat ... |
是没有必要的.
foo=$(sed 's/-/_/g' << EOF
1-2
3-4
EOF
)
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
15684 次 |
最近记录: |