Fix bug in getcommand introduced in PR 4299. Fixes #4279