我刚加入巴斯有人能告诉我我做错了什么吗?我在网上尝试了下面的正则表达式模式,它工作得很好。但是下面的Bash脚本拒绝匹配。
我需要从文本块的最后一行提取status:
的值,如下所示:
res=$(cat <<-EOM
Conducting pre-submission checks for my.zip and initiating connection to the Apple notary service...
Submission ID received
id: 573ebf8c-5434-4820-86c6-46adf01f81a9
Successfully uploaded file
id: 573ebf8c-5434-4820-86c6-46adf01f81a9
path: path-to.zip
Waiting for processing to complete.
Current status: Invalid.....Processing complete
id: 573ebf8c-5434-4820-86c6-46adf01f81a9
status: Invalid
EOM
)
# Get status -- need word "invalid" from this line: status: Invalid
status=""
regex='status:\s*(\w+)$'
[[ $res =~ $regex ]] &&
status=${BASH_REMATCH[1]}
echo "stat=$status"
1条答案
按热度按时间7rtdyuoh1#
x1c 0d1x您的
bash
版本不支持类似PCRE
的语法\w
。我会怎么做:
输出
正则表达式匹配如下:
status:
[[:space:]]*
(
[[:word:]]+
)
有关
POSIX
* 字符类 * 的文档,请参阅POSIX
规范的