title: bash extract xml attribute value using xmllint
body: <p>I am extracting an attribute value from xml file, but I get an error.
  I'd like to extract the value for <code>key="qua"</code> in the <strong>firstpart</strong> element. Here is my script, but below you find the errors:</p>
  
  <pre><code>#!/bin/bash
  
  myfile=$1
  
  myvar=$(echo 'cat //firstpart/step/category/id/info[@key="qua"]/@value' | xmllint --xpath "$myfile" | awk -F'[="]' '!/&gt;/{print $(NF-1)}')
  
  echo "$myvar"
  </code></pre>
  
  <p>how my xml file looks like:</p>
  
  <pre><code>&lt;?xml version='1.0' encoding='UTF-8'?&gt;
  &lt;firstpart&gt;
      &lt;step name="Home"&gt;    
          &lt;category name="one"&gt;
              &lt;id name="tools"&gt;
                  &lt;info key="qua" value="1"/&gt;        
              &lt;/id&gt;
          &lt;/category&gt;
      &lt;/step&gt;
      &lt;step name="Contact"&gt;    
          &lt;category name="two"&gt;
              &lt;id name="tools"&gt;
                  &lt;info key="qua" value="2"/&gt;        
              &lt;/id&gt;
          &lt;/category&gt;
      &lt;/step&gt;
      ...
  &lt;/firstpart&gt;
  &lt;secondpart&gt;
      &lt;step name="office"&gt;    
          &lt;category name="one"&gt;
              &lt;id name="tools"&gt;
                  &lt;info key="qua" value="100"/&gt;        
              &lt;/id&gt;
          &lt;/category&gt;
      &lt;/step&gt;
      &lt;step name="Contact"&gt;    
          &lt;category name="two"&gt;
              &lt;id name="tools"&gt;
                  &lt;info key="qua" value="200"/&gt;        
              &lt;/id&gt;
          &lt;/category&gt;
      &lt;/step&gt;
      ...
  &lt;/secondpart&gt;
  </code></pre>
  
  <p>the errors I get:</p>
  
  <pre><code>awk: run time error: negative field index $-1
      FILENAME="-" FNR=71 NR=71
  
  ./mybash.sh: line 3: $: command not found
  ./mybash.sh: line 4: $: command not found
  </code></pre>