Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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
like image 572
Mark Renouf Avatar asked Jan 24 '10 21:01

Mark Renouf


1 Answers

The cat ... | isn't necessary.

foo=$(sed 's/-/_/g' << EOF
1-2
3-4
EOF
)
like image 63
Ignacio Vazquez-Abrams Avatar answered Oct 21 '22 01:10

Ignacio Vazquez-Abrams