我对 unix shell 脚本相当陌生。尝试从 xpom.xml 捕获某些工件的版本信息但没有成功。
我无法在系统中安装任何额外的东西,检查是否安装了 xmllint。任何使用直接 unix 命令或 xmllint 的解决方案都值得赞赏。
文件=~/xpom.xml
<project xmlns=http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.generic</groupId>
<artifactId>genericlist</artifactId>
<packaging>pom</packaging>
<version>10.0.25</version>
<name>GenericRelease12.x.3</name>
<description>GenericRelRepo</description>
<dependencies>
<dependency>
<groupId>org.alpha</groupId>
<artifactId>alpha</artifactId>
<version>1.1.1</version>
<type>war</type>
</dependency>
<dependency>
<groupId>com.db</groupId>
<artifactId>oradatabase</artifactId>
<version>7.7.7</version>
<type>jar</type>
</dependency>
</dependencies>
</project>
我需要捕获 oradatabase artifactId 的版本。解决方案应返回 7.7.7。
我尝试跟随但没有成功(从这个网站获得这些提示并对其进行修改以满足我的需要:
尝试1:
xmllint --xpath '//project/dependencies/dependency[artifactId='oradatabase']/@value' xpom.xml
它抛出未知选项--xpath
尝试2:
artifactId=$(xmllint --format --shell "$file" <<< "cat //project/dependencies/dependency/artifactId/text()" | grep -v /)
if [[ $artifactId =~ ^(oradatabase)$ ]]
then
version=$(xmllint --format --shell "$file" <<< "cat //project/dependencies/dependency/artifactId/text()" | grep -v /)
echo "version is: " ${version}
else
echo "Not found"
fi
-- 返回未找到。
感谢您对此的任何帮助。