2

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. 
4

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
  • I was using exactly the same options with mintty 2.7.9 (x86_64-pc-cygwin) so it must be a bug. Thanks for your time Michael. – ndemou Oct 27 '17 at 13:09
0

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.