Bash if判断
Bash 中,判断某个变量是否在 指定 字符串中。
以下为用于根据IP判断机房
if ([[ $ip =~ "*.*.*" ]] || [[ $ip =~ "*.*.*" ]]); then idc="jyw" elif([[ $ip =~ "*.*.*" ]] || [[ $ip =~ "*.*.*" ]] || [[ $ip =~ "*.*.*" ]] || [[ $ip =~ "*.*.*" ]]); then idc="dzc" elif([[ $ip =~ "*.*" ]] || [[ $ip =~ "123.103" ]] || [[ $ip =~ "202.108" ]] || [[ $ip =~ "123.*.*" ]]); then idc="syq" elif([[ $ip =~ "124.*" ]] || [[ $ip =~ "*.*" ]] || [[ $ip =~ "124.2*" ]] ); then idc="sjhl" elif([[ $ip =~ "180.163" ]] || [[ $ip =~ "180.153" ]]); then idc="nh" elif([[ $ip =~ "42.62.*" ]] || [[ $ip =~ "42.*" ]]); then idc="jyw" else idc="jyw" fi