I haven’t done a very good job keeping up with features that have been added to Bash over the years. While sitting in on Hal Pomeranz’s Return of Command-Line Kung Fu talk at Open Source Bridge this year I picked up this gem:

$ for ((i=0; $i<1024; i++)); do
>  echo > /dev/tcp/localhost/$i && echo "tcp/$i is alive"
> done 2>/dev/null
tcp/22 is alive
tcp/80 is alive
…

I didn’t know Bash supported C-style for loops, so I’m glad to have learned of them. But I’m not quite sure how to feel about the magic /dev/tcp “files” – that seems potentially useful but so very perverse. Search for “/dev/tcp” in the Bash man page to read more about it (/dev/udp is also supported).