Check if the command exists before dereference

Docker-DCO-1.1-Signed-off-by: Guillaume J. Charmes <guillaume.charmes@docker.com> (github: creack)
Merge pull request #4394 from creack/fix_tty_ghost

Check if the command exists before dereference