如题,原脚本中判断的是传入的第一个参数$1,这里我改成了IPA,然后动态赋值,输出的 IPA 值也确实为 v6 ,但是判断为 v4 。请大家帮忙看看是哪里出错了
#!/bin/sh
IPA=`curl 'https://api64.ipify.org?format=json' | jq -r .ip`
echo $IPA
if [ "$IPA" != "${1#*:[0-9a-fA-F]}" ]; then
echo IPv6
elif [ "$IPA" != "${1#*[0-9].[0-9]}" ]; then
echo IPv4
else
echo "Unrecognized IP format '$1'"
fi
执行后的输出:
root@testbench:/home/testbench/userdata# ./ipv6.sh
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 47 100 47 0 0 48 0 --:--:-- --:--:-- --:--:-- 47
2409:8a66:b53:c761:c3be:b1b3:69d7:fb01
IPv4