Skip to content

Instantly share code, notes, and snippets.

@coderofsalvation
Created January 8, 2014 20:56
Show Gist options
  • Save coderofsalvation/8324521 to your computer and use it in GitHub Desktop.
Save coderofsalvation/8324521 to your computer and use it in GitHub Desktop.
check if port is a num and if it's privated (<1025), returns 0 on success, 1 otherwise (bashfunction)
# check if port is a num and if it's privated (<1025), returns 0 on success, 1 otherwise
# @param int portnumber
function isprivport()
{
[ -z "$1" ] && return 1
printf "%s\\n" "$1" | grep -v "[^0-9]" >/dev/null
if [ $? -eq 0 ]; then
[ $1 -gt 0 ] && [ $1 -lt 1025 ] && return 0 || return 1
else
return 1
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment