Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to suppress over-verbose xpath-output?

Tags:

shell

xml

xpath

I'm using xpath (as supplied in Mac OS X 10.9 usr/bin/xpath5.16) in a shell script to parse some values from an XML file which works really well. However it gives me some verbose output which I don't want to see in my script. I actually only want to store the result (the content of the attribute) in a variable.

content=$(xpath ../../AndroidManifest.xml /manifest/@android:versionCode)
echo "$content"

After execution the variable content indeed contains the content of the attribute, however there is also some verbose output I want to get rid of. Here it is:

Found 1 nodes:
-- NODE --

 android:versionCode="38"

Note: the "38" at the end of the output originates from the echo "$content" line the rest is the output of xpath.

like image 201
ubuntudroid Avatar asked Dec 09 '13 16:12

ubuntudroid


2 Answers

Found the solution. Simply append 2>/dev/null to the command:

content=$(xpath ../../AndroidManifest.xml /manifest/@android:versionCode 2>/dev/null)

Output:

 android:versionCode="38"
like image 87
ubuntudroid Avatar answered Sep 29 '22 09:09

ubuntudroid


From man xpath:

-q
    Be quiet. Output only errors (and no separator) on stderr.

Better use xpath -q ... instead of piping all stderr-messages. This will make sure actual errors will continue to be printed, but no other status output / node dividers.

like image 44
Jens Erat Avatar answered Sep 29 '22 09:09

Jens Erat