#!/bin/bash
STR=‘GNU/Linux is an operating system‘
SUB=‘Linux‘
if [[ "$STR" =~ ."$SUB". ]]; then
echo "It‘s there."
fi
答案是 It‘s there
下面这个是我脚本用到的,用正则表达式
if [ $src_ip = "47.112.15.82" ]
then
name="阿里云"
elif [ $src_ip = "113.16.167.157" ]
then
name="清湖中心"
elif [[ $src_ip =~ .*"180.139".* ]]
then
name="梁懿机器"
else
name="第三者"
fi