Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在使用类似于以下的案例陈述:
Case "$myvar" in [aA]) { #dostuff };; Esac
我的目标是捕获包含 a 或 A 的输入字符串的实例,而忽略字符串的其余部分。麻烦的是,给定包含其他内容(例如 ab)的输入,我的 case 语句没有捕获到该字符串。我确定问题出在我的正则表达式实现上,但我不知道如何解决。
bash 中的 case 语句采用 glob,而不是正则表达式。并且 glob 匹配整个字符串。因此,要查找字母“A”的任何实例,您可以:
case "$myvar" in *[aA]*) # do stuff ;; esac