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
.
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"
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With