直接上代码:
[root@center-me ~]# a="1" [root@center-me ~]# b="abcd1" [root@center-me ~]# [root@center-me ~]# if [[ $b =~ "$a" ]]; then echo yes; else echo no; fi yes [root@center-me ~]# [root@center-me ~]# a="2" [root@center-me ~]# if [[ $b =~ "$a" ]]; then echo yes; else echo no; fi no [root@center-me ~]#
——————————————
Done。