#793883 bash: clears console after running ssh

Package:
bash
Source:
bash
Description:
GNU Bourne Again SHell
Submitter:
Carsten Hey
Date:
2015-08-03 12:24:04 UTC
Severity:
normal
#793883#5
Date:
2015-07-28 14:11:54 UTC
From:
To:
16:03:32 <carstenh> Hi, clear_console normally does not clear an xterm, but after running su it does, and (run through skel.bash_logout) it also clears after running ssh on tty1.  You might use an other definition of console as I do, or
                    this is a bug.
16:03:44 <carstenh> Also, skel.bash_logout sometimes fails with exit code 1 although it should not, and it is neither set -e nor set -u safe.  I fixed this for you and added a workaround for the misbehaviour after running ssh on tty1:
16:03:49 <carstenh> http://paste.debian.net/plainh/7f08bc66
16:07:50 <carstenh> Do you consider skel.bash_logout as copyrightable (only the code)?  The only non-obvious thing in it is the undocumented option (the manpage misses them).
16:09:05 <doko> please file a bug report

#793883#8
Date:
2015-08-03 12:15:30 UTC
From:
To:
* Carsten Hey [2015-07-28 16:11 +0200]:

This is a .bash_logout problem, the code below fixes this.

This is actually a clear_console problem, the code below works around
this, and if clear_console would do what it should, it would still be
a significant performance improvement.

Maybe you should throw away clear_console and replace it with a simple
shell script that runs getopts, prints the message known from
clear_console if -q is not used and no terminal was detected (I would
have added a -v option instead and made -q default) and contains the
inner case snippet from the code below.


Use "${VAR-}", not "$VAR" and add "&& :" to commands that could fail.
Also fixed below.


Unless noted otherwise, anything below is too trivial to be
copyrightable.

# The author of the “if [ "$SHLVL" = 1 ]; then” part of below condition
# is Matthias Klose, see /usr/share/doc/bash/copyright on Debian or
# Ubuntu for copyright and license information.
if [ "${SHLVL-}|${SSH_CONNECTION-}" = "1|" ]; then
    case ${0##*/} in
    (-su|su)
        ;;
    (*)
        # This is a replacement for console_clear, which is broken.
        # After console_clear has been rewritten, it will be able to
        # replace below code.
        #
        # The glob to detect consoles below is:
        #   Copyright (C) 2011 Anton Zinoviev, and published under
        #   the license terms found in /usr/share/doc/expat/copyright,
        #   commonly known as MIT license.
        if [ -x /usr/bin/tty ]; then
            case $(/usr/bin/tty) in
            (/dev/tty[1-9]*|/dev/vc/[0-9]*|/dev/console|/dev/ttyv[0-9]*)
                [ -x /usr/bin/clear ] && /usr/bin/clear && :
                ;;
            esac
        fi
        ;;
    esac
fi

: