linux的bash shell中“=~”的作用是什么

Yin*_*ang -2 linux bash

正如标题所说,“=~”在 Linux 上运行的 bash shell 脚本中起什么作用?我在网上搜索,发现“==”检查相等性,“!=”检查不平等性。“=~”怎么样?我猜这可能是一些正则表达式匹配?

nu1*_*73R 5

=~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)