#!/usr/local/bin/nawk -f function quit() { system("rm -f " tmpfile) exit } BEGIN { while ((getline < (ENVIRON["HOME"] "/.netrc")) > 0) { if ($1 == "machine") hosts[n++] = $2 } if (! n) { print "No hosts found" exit } if (("mktemp ~/.ftpmenu.XXXXXX" | getline tmpfile) == 0) exit for (i = 0; i < n; i++) printf "%3d: %s\n", i + 1, hosts[i] > tmpfile for (;;) { system("less " tmpfile) for (;;) { prompt = "Host (1-" n ")" if (r != "") prompt = (prompt " [" r "]") prompt = (prompt ": ") printf prompt if ((getline < "/dev/tty") <= 0) quit() if ($0 != "") { r = ($0 ~ /^[0-9]+$/) ? $0 : -1 if ((r < 1) || (r > n)) { print "Error: invalid response" continue } } else if (r == "") { print "Error: empty value" continue } break } system("ftp " hosts[r - 1]) } } .