You're replying to a comment by Marco R..

November 03, 2008, 01:22

In "Pitfall: validate an IPv4 address" awk returns not-zero when the input is a valid IPv4 address and zero otherwise. That's because awk's boolean arithmetic assigns 1 to True and 0 to False.

This is not what a shell programmer would expect because shells usually act in the opposite way: true=0 and false=1.

Thus, the final "shell-compatible" script should be:

awk -F '[.]' 'function ok(n) {
  return (n ~ /^([01]?[0-9]?[0-9]|2[0-4][0-9]|25[0-5])$/)
}
{exit (! ( ok($1) && ok($2) && ok($3) && ok($4) ) )}'

However, I'd prefer to use something simpler:

function ok(n) {if (n ~ /[^[:digit:]]/)        return 1==0;return (nNot fully tested but should work the samemy 2 pennies ;)

Reply To This Comment

(why do I need your e-mail?)

(Your twitter name, if you have one. (I'm @pkrumins, btw.))

Type the word "rocket_100": (just to make sure you're a human)

Please preview the comment before submitting to make sure it's OK.