Lv2eof
Lv2eof

Reputation: 1949

Get xml_grep input from variables

I have the folowing environment variable: Var="<aaa>bbb</aaa>"
And I have the following file: Var.xml: <aaa>bbb</aaa>

If I issue the command: xml_grep 'aaa' Var.xml --text_only
I get: bbb

But if I issue the command: echo $Var | xml_grep 'aaa' --text_only
I get the error:
Couldn't open -:
No such file or directory at /usr/bin/xml_grep line 137.
at /usr/bin/xml_grep line 137.

My question is:
How can I get the input to xml_grep from variables?

Upvotes: 1

Views: 490

Answers (1)

Sundeep
Sundeep

Reputation: 23697

On shells that support process substitution, you can use <(command) to use the output of a command as a file.

So, modifying your example that works with file, it would be:

xml_grep 'aaa' <(echo "$var") --text_only

Upvotes: 1

Related Questions