Stop terminal auto executing when pasting a command

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 behaviour. However, in another answer, there is a real solution to the OP’s problem.


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).


Prior to pasting type a # then paste your line. It will not execute and you can remove the # and hit enter when the modifications have been completed.

Tags:

Command Line