正如标题所说,“=~”在 Linux 上运行的 bash shell 脚本中起什么作用?我在网上搜索,发现“==”检查相等性,“!=”检查不平等性。“=~”怎么样?我猜这可能是一些正则表达式匹配?
=~bash 正则表达式是否匹配
例子
$ [[ 45 =~ [0-9]+ ]] && echo "45 contains digits"
45 contains digits
$ [[ "hello" =~ [0-9]+ ]] && echo "hello doesnt contains digits"
$ [[ "hello" =~ [a-z]+ ]] && echo "hello contains alphabets"
hello contains alphabets
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2600 次 |
| 最近记录: |