bash copy/paste full line takes extra newline keystroke

Bug #1970644 reported by John Crown
24
This bug affects 5 people
Affects Status Importance Assigned to Milestone
Ubuntu Online
New
Undecided
Unassigned

Bug Description

===How to reproduce:

(Ubuntu 22.04 (brand new install). In an xterm or gnome-terminal, at the command-prompt '%' SHELL=/bin/bash):
% echo ls no_such_file
ls no_such_file

Now position the mouse I-bar cursor anywhere over the echoed text, then triple-click the mouse left-button, to copy the entire line.
The entire line highlights (this is good) to the right edge of the xterm window.
Now click the mouse middle-button, to paste the copied text.

The expected result is that the command is executed:
% ls no_such_file
ls: cannot access 'no_such_file': No such file or directory

But instead, the line is pasted, complete with newline (judging from the position of the xterm block cursor, now sitting at the beginning of the next line) -- but the command has not executed.
Now type the "enter" key (this should not be necessary), and the command now executes.

Another way to observe what the "paste" is actually pasting (type-in the command line (below, i.e. cat ... od ...), then paste the same line as before):
% cat - | od -cx --endian=big
ls no_such_file
0000000 l s n o _ s u c h _ f i l e \n
           6c73 206e 6f5f 7375 6368 5f66 696c 650a

... and you can see that the newline char ('0a' is there at the end of the pasted line)
(Make sure that what you copy-and-paste has exactly 16 characters in it, counting the newline)

===[ end of "How to reproduce" ]

Meanwhile, I get the correct behavior in tcsh.

(Whether using xterm or gnome-terminal, always succeeds in tcsh , always fails in bash)

To recap, an extra keystroke (the "enter" key (after the paste)) is required in /bin/bash shell.

This behavior (bash) is different from how copy-and-paste (full line) has worked for the last 30 years. Also, it is different from tcsh (which still works correctly)

thank you for your attention to this issue.

John Crown (jqc)
summary: - xterm copy/paste full line takes extra newline keystroke
+ bash copy/paste full line takes extra newline keystroke
Revision history for this message
John Crown (jqc) wrote :

Work-around:

Add the following line in ~/.inputrc :

set enable-bracketed-paste 0

This turns off the bracketed-paste (mis-) feature everywhere (i.e. in any Xterm opened after updating ~/.inputrc).
To turn off bracketed paste only in the current Xterm, do this:

% bind 'set enable-bracketed-paste 0'

(Explanation: the bug reported here is actually due to the "bracketed paste" functionality, which has been creeping forward over the last 10 or 15 years, apparently. Much discussed on the duckduckgo, it has its advocates and detractors. I will happily remain neutral, as long as there remains a way (as shown above) to shut this ill-conceived time-wasting behavior down. (Ok, last one. I'm not bitter.))

Revision history for this message
Brian Ronald (brianetta) wrote :

Thanks, John. You saved me a bunch of frustration.

Revision history for this message
Open Sense Solutions (opensense) wrote :

What is the best way to work around this problem globally at the system level, without having to add/change a file for each user?

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.