The command get executed without the need of pressing Enter. This can be dangerous sometimes...
无需按Enter键即可执行该命令。这有时会很危险......
Why is that and how can I prevent it?
为什么这样,我该如何预防呢?
3 个解决方案
#1
Because you paste new line character with it. It's sometimes can be useful, for example, you can copy/paste many commands (long multi-line scripts) at once.
因为你用它粘贴新的线条字符。它有时可能很有用,例如,您可以一次复制/粘贴许多命令(长多行脚本)。
Well, It has never occurred to me to prevent this particular behavior. It's normal and expected. WYPIWYG - what you paste is what you get.
好吧,我从未想过要防止这种特殊行为。这是正常的和预期的。 WYPIWYG - 你粘贴的是你得到的。
#2
You're pasting one or more newline characters. Other than simply not copy and pasting newline characters there are a few things you can do to work around this:
您正在粘贴一个或多个换行符。除了简单地不复制和粘贴换行符之外,还有一些方法可以解决这个问题:
-
For single-line commands, type "#" first, so the command will be commented out. You can then go back up and edit it.
对于单行命令,首先键入“#”,因此命令将被注释掉。然后,您可以返回并编辑它。
-
Use bash's (seemingly little-known) edit-and-execute-command feature. To invoke it you can hit
CTRL-x
CTRL-e
if you use emacs keybindings (the default) orESC v
if you use vi keybindings. This will invoke a text editor containing your current command-line. You can then paste into the editor, and edit the command. Once you save and quit the command(s) saved by the editor will be executed (if you want to abort either comment out all lines or completely clear the buffer). You can set which editor is used with either theFCEDIT
orEDITOR
environment variables.使用bash(看似鲜为人知的)编辑和执行命令功能。要调用它,如果使用emacs键绑定(默认值),则可以按CTRL-x CTRL-e;如果使用vi键绑定,则可以按ESC v。这将调用包含当前命令行的文本编辑器。然后,您可以粘贴到编辑器中,然后编辑命令。保存并退出后,将执行编辑器保存的命令(如果要中止注释掉所有行或完全清除缓冲区)。您可以设置与FCEDIT或EDITOR环境变量一起使用的编辑器。
#3
A quick way to prevent execution is to type the comment character #, then paste the command.
防止执行的一种快速方法是键入注释字符#,然后粘贴命令。
I often do that because I fat-finger when copying and grab extraneous characters.
我经常这样做是因为我在复制时抓住了手指并抓住了无关紧要的角色。
When you paste after the comment character, then the command is in the history buffer and you can edit it, uncomment it, and run it.
粘贴注释字符后,该命令位于历史记录缓冲区中,您可以对其进行编辑,取消注释并运行它。
--- reply to comment
---回复评论
You're right, this only works for single-line commands. If you have a multi-line one in the clipboard, you can pipe the clipboard data through sed.
你是对的,这只适用于单行命令。如果剪贴板中有多行文件,则可以通过sed管理剪贴板数据。
Stupid bash trick # 4 million and one:
愚蠢的bash技巧#400万和一:
prompt:$ xclip -o -selection clipboard | sed --regexp-extended 's/^(.*)$/# \1;/'
提示:$ xclip -o -selection clipboard | sed --regexp-extended的/^(.*)$/# \ 1; /'
will turn this:
会变成这样:
for i in *.JPG;
我在* .JPG;
do echo mv $i ${i/.JPG/.jpg};
做echo mv $ i $ {i / .JPG / .jpg};
done;
into this:
# for i in *.JPG;
#for for in * .JPG;
# do echo mv $i ${i/.JPG/.jpg};
#do echo mv $ i $ {i / .JPG / .jpg};
# done;
Which is really not worth the effort, but kinda fun ;>
这真的不值得努力,但有点有趣;>
#1
Because you paste new line character with it. It's sometimes can be useful, for example, you can copy/paste many commands (long multi-line scripts) at once.
因为你用它粘贴新的线条字符。它有时可能很有用,例如,您可以一次复制/粘贴许多命令(长多行脚本)。
Well, It has never occurred to me to prevent this particular behavior. It's normal and expected. WYPIWYG - what you paste is what you get.
好吧,我从未想过要防止这种特殊行为。这是正常的和预期的。 WYPIWYG - 你粘贴的是你得到的。
#2
You're pasting one or more newline characters. Other than simply not copy and pasting newline characters there are a few things you can do to work around this:
您正在粘贴一个或多个换行符。除了简单地不复制和粘贴换行符之外,还有一些方法可以解决这个问题:
-
For single-line commands, type "#" first, so the command will be commented out. You can then go back up and edit it.
对于单行命令,首先键入“#”,因此命令将被注释掉。然后,您可以返回并编辑它。
-
Use bash's (seemingly little-known) edit-and-execute-command feature. To invoke it you can hit
CTRL-x
CTRL-e
if you use emacs keybindings (the default) orESC v
if you use vi keybindings. This will invoke a text editor containing your current command-line. You can then paste into the editor, and edit the command. Once you save and quit the command(s) saved by the editor will be executed (if you want to abort either comment out all lines or completely clear the buffer). You can set which editor is used with either theFCEDIT
orEDITOR
environment variables.使用bash(看似鲜为人知的)编辑和执行命令功能。要调用它,如果使用emacs键绑定(默认值),则可以按CTRL-x CTRL-e;如果使用vi键绑定,则可以按ESC v。这将调用包含当前命令行的文本编辑器。然后,您可以粘贴到编辑器中,然后编辑命令。保存并退出后,将执行编辑器保存的命令(如果要中止注释掉所有行或完全清除缓冲区)。您可以设置与FCEDIT或EDITOR环境变量一起使用的编辑器。
#3
A quick way to prevent execution is to type the comment character #, then paste the command.
防止执行的一种快速方法是键入注释字符#,然后粘贴命令。
I often do that because I fat-finger when copying and grab extraneous characters.
我经常这样做是因为我在复制时抓住了手指并抓住了无关紧要的角色。
When you paste after the comment character, then the command is in the history buffer and you can edit it, uncomment it, and run it.
粘贴注释字符后,该命令位于历史记录缓冲区中,您可以对其进行编辑,取消注释并运行它。
--- reply to comment
---回复评论
You're right, this only works for single-line commands. If you have a multi-line one in the clipboard, you can pipe the clipboard data through sed.
你是对的,这只适用于单行命令。如果剪贴板中有多行文件,则可以通过sed管理剪贴板数据。
Stupid bash trick # 4 million and one:
愚蠢的bash技巧#400万和一:
prompt:$ xclip -o -selection clipboard | sed --regexp-extended 's/^(.*)$/# \1;/'
提示:$ xclip -o -selection clipboard | sed --regexp-extended的/^(.*)$/# \ 1; /'
will turn this:
会变成这样:
for i in *.JPG;
我在* .JPG;
do echo mv $i ${i/.JPG/.jpg};
做echo mv $ i $ {i / .JPG / .jpg};
done;
into this:
# for i in *.JPG;
#for for in * .JPG;
# do echo mv $i ${i/.JPG/.jpg};
#do echo mv $ i $ {i / .JPG / .jpg};
# done;
Which is really not worth the effort, but kinda fun ;>
这真的不值得努力,但有点有趣;>