Let's be very clear about this:
There is NO clean way to quit an application via the shell.
The standard command is kill (or killall for named processes), and like its name implies, it can be a bit brutal - the specifics lie in how each app responds to the kill command. Off hand, I don't know that answer, but I don't expect it to be good.
Indeed, a quick check here with:
killall -3 Microsoft\ Word
(where '-3' is the 'graceful' quit signal) does quit Word, and promptly launches Microsoft Diagnostics which thinks Word crashed and asks if you want to send a diagnostic report to Microsoft.
Therefore, it's likely that the only 'safe' way is via Apple Events (which could be sent via AppleScript or the shell's osascript command, but both will have the same issues you've likely already encountered - namely the various states of the applications in question, and whether they stop to ask if you want to save open documents, etc. Honestly, this is a big hit-or-miss game, dependent entirely on how the relevant developers have written their apps. Shell or AppleScript won't change that.