benibela / xidel

Command line tool to download and extract data from HTML/XML pages or JSON-APIs, using CSS, XPath 3.0, XQuery 3.0, JSONiq or pattern matching. It can also create new or transformed XML/HTML/JSON documents.
http://www.videlibri.de/xidel.html
GNU General Public License v3.0
674 stars 42 forks source link

Output to bash variable doesn't work (or isn't clear in the documentation) #90

Closed csandwith closed 2 years ago

csandwith commented 2 years ago

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

csandwith commented 2 years ago

Doh! missed the eval at the start. Working code looks like:

#!/bin/bash

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