5

I have a desktop shortcut that starts a cygwin bash script and I want the mintty terminal to stay open after my script terminates so that I can look at it's output. For this purpose I'm using the -h always mintty option[1].

The window does stay open but the output is unhelpfully cleared by mintty just as my script terminates(!!!). Seems like a bad joke. Am I missing something? I've verified this behavior even with a one line script with just an echo.


Note [1] -h is described like this in the man page:

-h, --hold never|start|error|always

Determine whether to keep the terminal window open when the command has finished and no more processes are connected to the terminal. 
ndemou
  • 1,280
  • 1
  • 13
  • 21

2 Answers2

5

I ran a few tests, and the -h always mintty option worked as expected; the screen did not get cleared and the window stayed open.

Here is the exact shortcut "Target" I used for running a script:

C:\cygwin64\bin\mintty.exe -h always /usr/bin/bash -l ~/helloworld.bash

I am using mintty 2.7.7 (x86_64-pc-cygwin).

Hopefully, upgrading mintty and/or using the syntax as shown above will fix things for you. If not, you could force a pause within the script itself by adding a read command like so:

echo 'Script end.  Press ENTER to close'
read
2

I was running my script with bash --login so on termination it implicitly calls /etc/bash.bash_logout which includes a line that runs /usr/bin/clear ("to increase privacy").


Credits: I found the answer in this bug report which includes this helpful explanation:

>  Hmm, the screen clearing is done by the latest /etc/bash.bash_logout:

# when leaving the console clear the screen to increase privacy   if
[ "$SHLVL" = 1 ]; then
    [ -x /usr/bin/clear ] && /usr/bin/clear   
fi
ndemou
  • 1,280
  • 1
  • 13
  • 21