Escape shell characters in query before running

Otherwise some characters, for example `?` and `!` used in Ruby keywords, confuse the shell.