Path: csiph.com!xmission!news.snarked.org!news.linkpendium.com!news.linkpendium.com!panix!usenet.stanford.edu!not-for-mail From: Tomas Janousek Newsgroups: gnu.bash.bug Subject: History not saved when closing terminal while bash is sourcing a script Date: Sat, 3 Aug 2019 17:05:29 +0200 Lines: 55 Approved: bug-bash@gnu.org Message-ID: References: <20190803150529.u5lf2tzvgo5sie7m@nomi.cz> NNTP-Posting-Host: lists.gnu.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="b5jc2qntopykam5p" Content-Transfer-Encoding: 7bit X-Trace: usenet.stanford.edu 1564846129 10390 209.51.188.17 (3 Aug 2019 15:28:49 GMT) X-Complaints-To: action@cs.stanford.edu To: bug-bash@gnu.org Envelope-to: bug-bash@gnu.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=nomi.cz; s=201904; t=1564844731; bh=nIAdpGFTxLVMat9VZfpRbS/RMJrlFNznN8ozVC0TES8=; h=Date:From:To:Subject:From; b=OEdEmW+oxlweAPpc5ep6mZW+sOqJ+ZgArQiWQ6oL+Jxhu7BDtVD/U3RtinPbYy8Zg WvNJJWfHTovg3gtyRTytu5JcwLouStjnjOP8kehqfNskPqPZpWlF0E48Nd4nvfcsUl h0Z39Y9/dLRNUvkafmtIcJUlsWbNYUbYH4sE5GjP/tKowb/W3blox60EdLMYvrp1qE rWip5z08Q2HYWiddz3REp+8rZKsw2Aer4uwVUjfUpg7vD/RjhJ77lG8YFwnb9Irtd9 4RsElNm8MugdAsXYsf6v29AacYX+KNoRpGutN/qZGagGxGWFIose7zAIwteqKW+DwX h2jDg2jDGNdXw== Content-Disposition: inline User-Agent: NeoMutt/20180716 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 81.31.33.35 X-Mailman-Approved-At: Sat, 03 Aug 2019 11:28:47 -0400 X-BeenThere: bug-bash@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Bug reports for the GNU Bourne Again SHell List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Mailman-Original-Message-ID: <20190803150529.u5lf2tzvgo5sie7m@nomi.cz> Xref: csiph.com gnu.bash.bug:15291 --b5jc2qntopykam5p Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Hello, today I was wondering why I'm sometimes losing history entries and found = out that bash (5.0.3(1)-release, on Debian testing) won't save the history fi= le on closing the terminal window if it's currently sourcing something. I'm attaching a script that uses tmux to simulate the scenario. On my system,= only "test 1" is printed, not "test 2" as expected. I think this is a bug. A more realistic example (what actually caused my losing of history entri= es) is Midnight Commander: many distros install the following file into /etc/profile.d: https://github.com/MidnightCommander/mc/blob/master/contr= ib/mc.sh.in which sources https://github.com/MidnightCommander/mc/blob/master/contrib= /mc-wrapper.sh.in so that when one exits mc, the outer shell chdirs to the last directory browsed in mc. But this means one loses all history entries from the sess= ion before invoking mc. (Workaround for mc: invoke history -a before sourcing mc-wrapper. Or disa= ble this wrapper entirely.) Regards, --=20 Tom=C3=A1=C5=A1 Janou=C5=A1ek, a.k.a. Pivn=C3=ADk, a.k.a. Liskni_si, http= ://work.lisk.in/ --b5jc2qntopykam5p Content-Type: application/x-sh Content-Disposition: attachment; filename="test2.sh" Content-Transfer-Encoding: quoted-printable #!/usr/bin/env bash=0A=0Atmux_session=3D"$$"=0A=0Asourced_script=3D$(mktemp= )=0Atrap 'rm "$sourced_script"' EXIT=0A=0Acat >"$sourced_script" <<-\EOF=0A= #!bash=0A cat >/dev/null=0AEOF=0A=0Atmux new-session -s "$tmux_session" -n= win1 -d=0Asleep 0.5=0Atmux send-keys -t "$tmux_session:win1" -l "# $tmux_s= ession: test 1"$'\n'=0Asleep 0.5=0Atmux kill-window -t "$tmux_session:win1"= =0Asleep 0.5=0Atmux new-session -s "$tmux_session" -n win2 -d=0Asleep 0.5= =0Atmux send-keys -t "$tmux_session:win2" -l "# $tmux_session: test 2"$'\n'= =0Asleep 0.5=0Atmux send-keys -t "$tmux_session:win2" -l "source $(printf "= %q" "$sourced_script")"$'\n'=0Asleep 0.5=0Atmux kill-window -t "$tmux_sessi= on:win2"=0Asleep 0.5=0A=0Agrep "^# $tmux_session: " ~/.bash_history=0A --b5jc2qntopykam5p--