Stop terminal auto executing when pasting a command

Right, this is a slightly annoying feature because something this happens, and other times it doesn't, very odd.

I paste a command into the terminal with a view to tweaking its arguments, and sometimes it executes the second I paste it. Sometimes it doesn't.

This ranges from embarrassing ( posting nonsensical comments on an IRC ) to dangerous.

How can I shut this feature off for good? I never, never, never want the terminal to auto execute when I paste to it.


Solution 1:

There's no auto execution. You probably are also copying a line break (or more) after the command.

If you paste a command with a break, the shell (command line) thinks that you hit the break (Enter, Return) button by yourself.


This answer only explains why OP is getting the undesired behavior. However, in another answer, there is a real solution to the OP’s problem.

Solution 2:

One real solution is to open editing mode with ctrl-x ctrl-e and then safely paste your clipboard into your editor of choice (commonly emacs or vim). After you are done editing the command, save and exit and it will run in the command line. This is a good habit for long or complex commands, especially when pasting commit hashes into git commands, and can help you avoid some scary results in the long run.

The editor can be changed by setting the VISUAL and EDITOR variables (these have different meanings, see here).