_ @ [^ @] * @in bash

everyone, I have a problem with this expression in a shell script :

expr "$VERSION" : " _@ [^@]*@" 

Who can tell me what the "@" means here?

+4
source share
2 answers

From 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. 

@ is just @ because it does not really matter in the regular expression. In this way,

 expr _@foo @ : " _@ [^@]*@" 

will succeed and print 6 (this is the number of matching characters); while

 expr _x@foo @ : " _@ [^@]*@" 

will output 0 and return an error code in $? because he cannot match anything.

If you are not familiar with regular expressions, then one of the examples in your example means: an underscore ( _ ) follows two at ( @ ) characters that let in any number of unsigned characters.

+1
source

This is just literal @ . @ does not really matter in regex, although it may be in $VERSION .

Matches an underscore followed by @, followed by zero or more @ characters, and then @. "

+1
source

All Articles