I wrote an
.command script that when I launch it, it just exits and it's to quick for me to see what's going on. How do I keep it open?
When you double click a
.command in the Finder, the Terminal opens and runs
/path/to/your.command ; exit; The
exit at the end exits the shell, and you have Terminal's preferences set to close the window when this happens.
- Go to Terminal -> Preferences -> Settings -> Whichever Theme is marked as the Default -> Shell -> When the shell exits: and choose "Don't close the window".
Alternatively, if you don't want to change Terminal's preferences:
- If your command outputs something to STDOUT that you want to read after the command exits, you can pipe the command's output through
less, which will then stay open allowing you to scroll around through the output with the arrow keys until you quit it with
q. Just add
|lessto the end of the command in your script.
- Found a more flexible option. If piping something through
lessisn't practical for whatever reason, or your script is too complicated, you can add a last command that waits for input from the user before completing. I used
$ read -n 1 -p "Done. Press any key to exit. "
(Wait for one character of input while displaying the prompt.)