我碰到了一个 Nagios 检查脚本,它是由一个已经离开我公司的人编写的,那里有一个操作员,我不明白它的用途。这是 shell 脚本的相关部分:
if [[ "$URL" =~ $ACTIVE ]] && [[ "$URL2" =~ $ACTIVE2 ]]; then
echo "OK: $HOST is ACTIVE in the Load Balancer"
exit 0
我的问题是:
这是什么=~
?
我在网上查了一下,发现它是按位“翻转操作数中的位”,但我不明白在哪里以及如何使用它,您能详细说明一下吗?
编辑#1:这是完整的脚本:
#!/bin/bash
#Purpose: Checks if proxy is active in the LB
#Date: May 09, 2011
#Variables
HOST=$1
URL=`wget --timeout=60 -w 3 -qO- http://$HOST:8080/proxy/keepalive?file=/workspace/temp/1`
URL2=`wget --timeout=60 -w 3 -qO- http://$HOST:8080/proxy/keepalive?file=/workspace/temp/1.txt`
ACTIVE="1"
ACTIVE2="ppp"
LOG="/tmp/PROXY-LB.log"
#Begin Code
if [ -z $HOST ]; then
echo "You must specify IPADDRESS (e.g. 68.67.174.34)"
exit 3
fi
if [[ "$URL" =~ $ACTIVE ]] && [[ "$URL2" =~ $ACTIVE2 ]]; then
echo "OK: $HOST is ACTIVE in the Load Balancer"
exit 0
else
echo "*** Problem: $HOST is out from the Load Balancer"
echo "`date`: *** HOST $HOST is out from the Load Balancer" >> $LOG 2>&1
exit 2
fi
#END
我的问题是,编码器不能使用这个(没有~
)吗?
if [[ "$URL" = $ACTIVE ]] && [[ "$URL2" = $ACTIVE2 ]]; then
编辑#2:以下是我尝试的一些示例:
$ d="hello"
$ [[ "$d" =~ *ll* ]] && echo "yes"
$ [[ "$d" =~ he* ]] && echo "yes"
yes
$ [[ "$d" =~ *lo ]] && echo "yes"
$
编辑#3:好的,我做了更多的测试,我相信我现在明白了:
$ [[ "$d" =~ he* ]] && echo "yes"
yes
$ [[ "$d" =~ *lo ]] && echo "yes"
$ [[ "$d" =~ h* ]] && echo "yes"
yes
$ [[ "$d" =~ lo$ ]] && echo "yes"
yes
$ [[ "$d" =~ ^he ]] && echo "yes"
yes
$ [[ "$d" =~ [a-z]ll[a-z] ]] && echo "yes"
yes
$
谢谢大家的帮助和信息!