user2939526
user2939526

Reputation: 21

What am i doing wrong? XML and bash

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

Answers (2)

user1019830
user1019830

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

Martin Honnen
Martin Honnen

Reputation: 167696

Exchange the quote delimiters xmllint --xpath "/rates/currency[code='$code1']/rate/text()" rates.xml.

Upvotes: 1

Related Questions