What's the easiest way to find an unused local port?
Currently I'm using something similar to this:
port=$RANDOM quit=0 while [ "$quit" -ne 1 ]; do netstat -a | grep $port >> /dev/null if [ $? -gt 0 ]; then quit=1 else port=`expr $port + 1` fi done
It feels awfully roundabout, so I'm wondering if there's a more simple path such as a builtin that I've missed.