bash单词合并_如何在Bash命令中快速更改第一个单词?

bash单词合并

bash单词合并_如何在Bash命令中快速更改第一个单词?

If your workflow is populated with a lot of repetitive actions, then it never hurts to look for ways to improve and streamline your workflow. Today’s SuperUser Q&A post has some helpful suggestions for a reader seeking to improve his workflow.

如果您的工作流程中包含许多重复性操作,那么寻找改进和简化工作流程的方法就不会有什么坏处。 今天的“超级用户问答”帖子为寻求改善工作流程的读者提供了一些有用的建议。

Today’s Question & Answer session comes to us courtesy of SuperUser—a subdivision of Stack Exchange, a community-driven grouping of Q&A web sites.

今天的“问答”环节由SuperUser提供,它是Stack Exchange的一个分支,该社区是由社区驱动的Q&A网站分组。

Screenshot courtesy of Matt Joyce (Flickr).

屏幕截图由Matt Joyce(Flickr)提供

问题 (The Question)

SuperUser reader coin wants to know how to quickly change the first word in a bash command:

超级用户阅读器硬币想知道如何快速更改bash命令中的第一个单词:

I would like to improve my workflow in bash and realized that I often want to execute the same command to a different executable.

我想改善bash的工作流程,并意识到我经常想对不同的可执行文件执行同一命令。

Some Examples

一些例子

1.) Git

1.)Git

bash单词合并_如何在Bash命令中快速更改第一个单词?

2.) Bash

2.)重击

bash单词合并_如何在Bash命令中快速更改第一个单词?

I know that I can hit Ctrl+a then Del to remove the first word, but I am wondering if there is a quicker way to do it.

我知道我可以先按Ctrl + a再按Del来删除第一个单词,但是我想知道是否有更快的方法。

Is there a quicker way for coin to change the first word in bash commands?

硬币有更快的方法来更改bash命令中的第一个单词吗?

答案 (The Answer)

SuperUser contributors Spiff, Hastur, jjlin. and Gustavo Giraldez have the answer for us. First up, Spiff:

超级用户贡献者Spiff,Hastur和jjlin。 Gustavo Giraldez为我们提供了答案。 首先,Spiff:

!$ expands to the last word of your previous command. So you could do:

!$扩展到上一个命令的最后一个单词。 因此,您可以执行以下操作:

bash单词合并_如何在Bash命令中快速更改第一个单词?

Or

要么

bash单词合并_如何在Bash命令中快速更改第一个单词?

Your examples happened to only repeat the last word, so !$ worked fine. If you actually had a lot of arguments that you wanted to repeat, and you just wanted to change the first word, you could use !*, which expands to all words of the previous command except the zeroth.

您的示例碰巧只重复了最后一个字,所以!$可以正常工作。 如果您实际上有很多要重复的参数,并且只想更改第一个单词,则可以使用!*,它扩展为除零以外的上一个命令的所有单词。

See the “HISTORY EXPANSION” section of the bash man page. There is a lot of flexibility there.

请参见bash手册页的“ HISTORY EXPANSION”(历史扩展)部分。 那里有很多灵活性。

Followed by the answer from Hastur:

接下来是Hastur的答案:

I would like to add a warning (see the answer from Spiff above). With !$, you do not have full visual control of the line you are running. The results can be harmful sometimes, especially if you incur a misprint. It takes what it needs from the history to expand on.

我想添加一个警告(请参见上面Spiff的回答)。 使用!$,您将无法完全直观地控制正在运行的行。 有时结果可能是有害的,尤其是在打印错误的情况下。 它需要从历史中获得所需的扩展。

So if you write the last command with a blank space at the beginning, then this command will probably not finish from the history. When you execute your new command with !$, the shell will not take the parameters from the last command line typed, but only from the last part of the history.

因此,如果您在末尾写上最后一个命令,则该命令可能不会从历史记录中结束。 当用!$执行新命令时,shell将不会从键入的最后一个命令行中获取参数,而只会从历史记录的最后一部分中获取参数。

Here are some more helpful words and commands.

这是一些更有用的单词和命令

Then the answer from jjlin:

然后jjlin的答案:

Ctrl+a to go to the beginning of the line, then Alt+d to delete the first word.

Ctrl + a转到行的开头,然后按Alt + d删除第一个单词。

And our final answer from Gustavo Giraldez:

我们对古斯塔沃·吉拉尔德斯(Gustavo Giraldez)的最终回答是:

The delete word shortcut is actually Meta+d, and Meta is usually mapped to Alt on Linux machines. On platforms where this is not the case, an alternative to get the Meta modifier is to use Esc as a prefix. You can read more about the Meta Key here.

删除单词快捷方式实际上是Meta + d ,并且Meta通常在Linux计算机上映射到Alt 。 在不是这种情况的平台上,获取Meta修饰符的另一种方法是使用Esc作为前缀。 您可以在此处阅读有关元**的更多信息。



Have something to add to the explanation? Sound off in the comments. Want to read more answers from other tech-savvy Stack Exchange users? Check out the full discussion thread here.

有什么补充说明吗? 在评论中听起来不错。 是否想从其他精通Stack Exchange的用户那里获得更多答案? 在此处查看完整的讨论线程

翻译自: https://www.howtogeek.com/207955/how-to-quickly-change-the-first-word-in-a-bash-command/

bash单词合并

相关文章:

  • 2021-06-18
  • 2021-11-27
  • 2022-12-23
  • 2022-02-21
  • 2022-12-23
  • 2021-04-23
  • 2022-02-17
  • 2021-06-03
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-09-07
  • 2022-12-23
  • 2021-08-22
相关资源
相似解决方案