This looks like a case of standard input inadvertent consuming.
Anything you paste in an interactive session is standard input data available to the command running in the foreground at that moment, and is normally shared by (and available to) all and any command you may be running in sequence, however quickly (or slowly) you may be able to type/paste. Each of the commands has its chance to consume part or all of the standard input data that happens to be available at the time of its execution.
sudo
is indeed one of those commands that will actively eat up all its standard input if it is configured to do so, which may well be the case for security reasons especially in enterprise setups. If this is the case for you, sudo
is consuming whatever text (i.e. the subsequent commands) you have pasted in.
If you are allowed to see the /etc/sudoers*
file(s) of the host you're experiencing that behavior on, check them whether they possibly have a Defaults
line setting either use_pty
or log_input
(or even both), for ALL
, or perhaps for your account or group, or even just for that exact command you're running through sudo
. As a matter of fact, it may actually even be some other system-wide plugin set in /etc/sudo.conf
, if the system administrator has been so inclined (unlikely, but possible).
Anyhow, you should be able to work-around that behavior by simply wrapping your paste within a sub-shell:
Just start by typing an open parentheses ( at the regular prompt of whatever shell you're using, then press Enter. You'll see the so-called "PS2" (aka "more input needed") prompt, which typically is >
, where you can keep typing commands at will and, of course, also pasting them from your clipboard just as they are. These commands will not be run immediately, they will rather be "enqueued" in the sub-shell started by the open parentheses until you end it explicitly. When you're done typing/pasting, finish by typing the close parentheses ) and again Enter, which ends the sub-shell.
Only at that point will your pasted commands finally run, without being "eaten up" by any one of them in midst (sudo
or else) that might be consuming standard input as per its normal (or special) behavior. This is because all your relevant standard input (i.e. your pasting) will have already been consumed by the "enqueuing" sub-shell and thus sudo
will have nothing to "eat up".
Note finally that in your case enable-bracketed-paste on
would be your friend, as that essentially makes bash
detect pasted text, differentiating it from typed text, aided by the terminal emulator (as long as the terminal emulator does offer such feature).
As to the reason why ksh
seems to be working "correctly", I haven't delved into its internals but, at a first glance of strace
-ing it, it appears to be reading bufferfuls of standard input, probably tokenizing it into single commands to run one by one, as opposed to reading-and-executing standard input in the typical streamlined fashion.
As to screen
disregarding enable-bracketed-paste on
altogether, I'm not an avid user of screen
myself, but I can tell as much: it's clearly a very "rich" piece of software terminal-wise, it may act as a terminal emulator itself, and as such it might interfere with (e.g. ignore and strip away) the escape-codes that bash
sends/receives to/from the terminal emulator for the bracketed-paste feature.
enable-bracketed-paste
is alreadyOff
enable-bracketed-paste
setting.