Refactor cmd_select() into two shorter functions.

The first does basic argument checking, then calls the second to do
the actual select if appropriate.
Merge branch 'master' into select-refactor

Master had moved ahead. Preparing for pull request.
Merge branch 'select-refactor'