linux shell 如何约等于字符串

时间:2020-11-06 02:40:24   收藏:0   阅读:30
这个以后肯定用的上的,直接放命令了

#!/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
评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!