Home > OS >  Bash shell string matching problem
Bash shell string matching problem

Time:09-23

Bash shell string matching problem

The pattern='^ \ d_'
STR='00 _abc'

If [[$STR=~ $patten]] # no matter have no Spaces before and after the operation, enter either all right or all wrong, no Spaces, matching passed, and I just want to match a number, a space, matching pass, the estimate is wrong expression
Then
Echo 'succ'
Fi;

CodePudding user response:

An alternative

^ patten='[0-9]'

If the [[$(echo $STR | awk "/$pattern/{1} print")]]
  • Related