iPhone and Linux

Sunday, February 28, 2010

Whatis it, man?

The "man" command is used to read UNIX manual pages and "whatis" gives you a brief description of a command taken from the NAME field of the man page. The iPhone lacks both commands, but these work ok.

#! /bin/sh
links -dump http://unixhelp.ed.ac.uk/CGI/man-cgi?${1} | grep -A 1000 NAME | sed 's/^[ \t]*//'
I actually like that because it's easier to grep the output, but adding a pipe to "less" more accurately approximates the real command. You could probably roll the grep into the sed command, but that's one of those things where I don't mind spending an extra one-thousandth of a second execution time to keep from having to craft a better sed one-liner.

#! /bin/sh
links -dump http://unixhelp.ed.ac.uk/CGI/man-cgi?${1} | grep "\- " | head -1 | sed 's/^[ \t]*//'
Let's test it.
# whatis ifconfig
ifconfig [] (8) - configure a network interface
# ./my_whatis ifconfig
ifconfig - configure a network interface
Close enough.

Blog Archive