linux shell 如何约等于字符串

这个以后肯定用的上的,直接放命令了

#!/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

猜你喜欢

转载自blog.51cto.com/12092988/2547176