两个不同字符串的 case 语句?
我不知道提出这个问题的最佳方法,但这是我想要工作的代码:
case $MESSAGE in
?Trcx!~*PRIVMSG*[${Nick}|${AltNick}]*[nN][mM]ap*)
echo "Some Code";;
*)
echo "Some Other Code";;
esac
我将如何使它工作?不起作用的部分是 [${Nick}|${AltNick}] 我希望表达式对 $Nick 和 $AltNick 变量都有效。非常感谢任何帮助!
I don't know the best way to form this question, but here's the code I want to work:
case $MESSAGE in
?Trcx!~*PRIVMSG*[${Nick}|${AltNick}]*[nN][mM]ap*)
echo "Some Code";;
*)
echo "Some Other Code";;
esac
How would I make it work? The part that is not working is the [${Nick}|${AltNick}] I want the expression to be valid for both the $Nick and $AltNick var. Any help is greatly appreciated!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
Bash glob 模式记录在此处。
您想要这个:
@(patt1|patt2)
。请注意,必须启用
extglob
shell 选项。Bash glob patterns are documented here.
You want this:
@(patt1|patt2)
.Note the
extglob
shell option must be enabled.在 glob 模式中,如果没有 Bash 的“extglob”功能,则无法使用括号对子模式进行分组 - 当然更不能使用方括号。 Bourne 兼容的方式是分成两种不同的模式。
In glob patterns, without Bash's "extglob" feature, you cannot group a subpattern with parentheses - and certainly not with square brackets. The Bourne-compatible way is to split into two distinct patterns.
Bash 执行大小写模式匹配,就像文件名匹配一样,而不是正则表达式匹配。如果这就是你想要的,那么问题就解决了。
但是,如果您想要正则表达式匹配,也许您可以尝试 [[ expression ]] 复合命令来实现您的目标,它提供了用于正则表达式匹配的 =~ 运算符。
Bash performs case pattern matching just like filename matching, not regular expression matching. If that's what you want, then problem solved.
However, if you want a regular expression match, perhaps you could try the [[ expression ]] compound command to achieve your goals, which offers the =~ operator for regular expression matching.