以下是我的 shell 脚本的片段 -
regex="<version>([0-9]*)\.([0-9]*)\.([0-9]*)([^<]*)<\/version>.*"
#some unrelated lines of code
echo $(grep -m 1 "<version>" $1)
if [[ $(grep -m 1 "<version>" $1) =~ $regex ]]
then
main_version = "${BASH_REMATCH[1]}"
feature_version = "${BASH_REMATCH[2]}"
patch_version = "${BASH_REMATCH[3]}"
tag = "${BASH_REMATCH[4]}"
else
echo "$1: Version not Found" >&2
fi
但它向我显示了以下输出 -
<version>1.1.7-release</version> <!-- ABC version -->
abc/xyz/pom.xml: Version not Found
但根据我的理解,regex
应该与输出相匹配grep
(我将其回显到终端以获得更好的清晰度)。那么有人能告诉我我做错了什么吗?