我不确定我做错了什么,它不起作用的原因是没有意义的:
这个我确实得到了预期的SSH结果
if [ "Hennopsview" != "2 - LAN" ] && [ "Hennopsview" != "1 - WAN" ] \
&& [ "Hennopsview" != "Cross Connect" ]; then
if [[ "Hennopsview" =~ /pptp/g ]]; then
echo "No Match 2"
else
ssh admin@192.168.0.1 ':put [/interface eoip get [/interface eoip find name="Hennopsview"] remote-address]'
fi
else
echo "No Match"
fi
然而,下面的一个并没有给我匹配 2 的回声
if [ "<pptp-hennopsview>" != "2 - LAN" ] && [ "<pptp-hennopsview>" != "1 - WAN" ] \
&& [ "<pptp-hennopsview>" != "Cross Connect" ]; then
if [[ "<pptp-hennopsview>" =~ /pptp/g ]]; then
echo "No Match 2"
else
ssh admin@192.168.0.1 ':put [/interface eoip get [/interface eoip find name="<pptp-hennopsview>"] remote-address]'
fi
else
echo "No Match"
fi
这个正则表达式有什么问题?
但是,以下修复了第二个请求
if [ "<pptp-hennopsview>" != "2 - LAN" ] && [ "<pptp-hennopsview>" != "1 - WAN" ] \
&& [ "<pptp-hennopsview>" != "Cross Connect" ]; then
if [[ "<pptp-hennopsview>" =~ [pptp] ]]; then
echo "No Match 2"
else
ssh admin@154.127.117.218 ':put [/interface eoip get [/interface eoip find name="<pptp-hennopsview>"] remote-address]'
fi
else
echo "No Match"
fi
但后来打破了原来的
if [ "Hennopsview" != "2 - LAN" ] && [ "Hennopsview" != "1 - WAN" ] \
&& [ "Hennopsview" != "SDA - Cross Connect" ]; then
if [[ "Hennopsview" =~ [pptp] ]]; then
echo "No Match 2"
else
ssh admin@154.127.117.218 ':put [/interface eoip get [/interface eoip find name="Hennopsview"] remote-address]'
fi
else
echo "No Match"
fi
我明白使用“[pptp]”是字符匹配而不是单词。为什么用“/”替换“[”不能解决问题?