Command to close terminal window
Open Terminal.
Go to Terminal → Preferences….


Select the Settings tab, then your profile, and choose the Shell tab.
Set When the shell exits to Close if the shell exited cleanly.