Bash 中的动态 Case 语句
我将如何编写:
PreviousInput='@(User1 | User2 | User3)*#channel'
###############################
Expression="*${PreviousInput}*"
case $Input in
$Expression )
Do_Something ;;
*)
Do_Something_Else ;;
esac
我真的很想使用 case 语句,因为我已经在 case 语句中投入了很多逻辑,并且真的不想重写它。我在想,我可以以某种方式使用全局模式,但真的不知道该怎么做。有什么建议吗?任何帮助表示赞赏。
How would I go about writing:
PreviousInput='@(User1 | User2 | User3)*#channel'
###############################
Expression="*${PreviousInput}*"
case $Input in
$Expression )
Do_Something ;;
*)
Do_Something_Else ;;
esac
I would really like to use a case statement because I have a lot of logic already invested in the case statement, and really don't want to rewrite it. I was thinking that somehow I could use glob patterns, but don't really know how I would do that. Any suggestions? Any help is appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
bash 手册说:
因此,我不认为您的示例不应该完全等同于
只要您设置了
shopt -s extglob
即可执行您想要的操作,正如 shellter 所说。The bash manual says:
So I don't see any reason that your example shouldn't be exactly equivalent to
which should do what you want as long as you have
shopt -s extglob
set, as shellter says.