Reputation: 21
This is code i am trying to make work:
echo "type in code"
read code1
echo (xmllint --xpath '/rates/currency[code="$code1"]/rate/text()' rates.xml)
It prints "XPath set is empty" It is supposed to print out the rate from my xml document. Which rate to print is determined by currency code (AUD, USD, EUR etc.). If it would be typed like that:
echo (xmllint --xpath '/rates/currency[code="GBP"]/rate/text()' rates.xml)
It would echo the correct rate for the currency which code is GBP.
Why is that? How to fix it?
Upvotes: 0
Views: 71
Reputation:
Use double quotes around the query string so that $code
gets expanded to its value inside the string:
echo $(xmllint --xpath "/rates/currency[code=\"$code1\"]/rate/text()" rates.xml)
Upvotes: 1
Reputation: 167696
Exchange the quote delimiters xmllint --xpath "/rates/currency[code='$code1']/rate/text()" rates.xml
.
Upvotes: 1