I am converting my script from bash to dash... and have problem getting the return code of a function.
#!/bin/sh
check_ip() {
local netbit=`echo "$1" | awk -F\/ '{print $1}'`
local netmask=`echo "$1" | awk -F\/ '{print $2}'`
if case "$netbit" in
*[!.0-9]* | *.*.*.*.* | *..* | [!0-9]* | *[!0-9] ) false ;;
*25[6-9]* | *2[6-9][0-9]* | *[3-9][0-9][0-9]* | *[0-9][0-9][0-9][0-9]* ) false;;
*.*.*.* ) true ;;
* ) false ;;
esac; then
if [ ! -z "$netmask" ] ; then
if [ "$netmask" -ge 1 ] && [ "$netmask" -le 32 ] ; then
return 0
else
return 1
fi
else
return 0
fi
else
return 1
fi
}
# this is working without the [] thing.
if check_ip "$1" ; then
echo ok
else
echo no
fi
looked up the similar script from another machine, and it has no [] as @barmar suggested. all working now. thank you very much.