每个人,我在shell脚本中都有一个关于这个表达式的问题
expr "$VERSION" : "_@[^@]*@"谁能告诉我"@“代表什么?
发布于 2013-02-20 03:55:40
来自man expr
expr1 : expr2
The ``:'' operator matches expr1 against expr2, which must be a
regular expression. The regular expression is anchored to the
beginning of the string with an implicit ``^''. expr expects
"basic" regular expressions, see re_format(7) for more informa-
tion on regular expressions.@只是@,因为它在正则表达式中没有特殊的意义。因此,
expr _@foo@ : "_@[^@]*@"将成功,并输出6 (它是匹配字符的数量);
expr _x@foo@ : "_@[^@]*@"将输出0并返回$?中的失败代码,因为它无法匹配任何内容。
如果您不熟悉正则表达式,那么在示例中给出的一个表达式的意思是:一个下划线(_)在两个符号(@)后面加上任意数量的非符号字符。
发布于 2013-02-20 03:53:13
这只是一个字面上的@。@在正则表达式中没有特殊的意义,尽管它在$VERSION中可能有。
匹配“下划线”,后面是@,后面是零或多个非字符,后面跟着@。
https://stackoverflow.com/questions/14971976
复制相似问题