Cody S
Cody S

Reputation: 4824

Xidel output to bash variable

According to the Xidel documentation, I'm under the impression that the following code should work, and should produce an output that I can access in the BASH variable "bar":

#!/bin/bash


TEST='<foo><bar>test</bar></foo>'
xidel $TEST -e 'bar:=//bar' --output-format=bash
echo "Result: ${bar}"

However, the output I get when executing this code is:

**** Processing: data:,<foo><bar>test</bar></foo> ****
** Current variable state: **
bar='test'
Result:

It's strange because Xidel is clearly printing its current variable state to include my variable...so I must not be accessing it correctly? How do I access it now, if not with $bar

Edit:

Gordon Davisson's comment below is correct - I misread the documentation. Working code looks like this:

#!/bin/bash


TEST='<foo><bar>test</bar></foo>'
eval $(xidel $TEST -e 'bar:=//bar' --output-format=bash)
echo "Result: ${bar}"

Upvotes: 1

Views: 217

Answers (1)

Philippe
Philippe

Reputation: 26737

Is this what you want to achieve ?

TEST='<foo><bar>test</bar></foo>'
bar="$(xidel "$TEST" -e '//bar')"
echo "Result: ${bar}"

Upvotes: 1

Related Questions