A sessão de perguntas e respostas de hoje nos é oferecida por cortesia do SuperUser, uma subdivisão do Stack Exchange, um agrupamento de sites de perguntas e respostas conduzido pela comunidade.
Screenshot cortesia de Matt Joyce (Flickr).
A questão
A moeda do leitor SuperUser quer saber como alterar rapidamente a primeira palavra em um comando 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.
Some Examples
1.) Git
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.
Existe uma maneira mais rápida para a moeda mudar a primeira palavra nos comandos do bash?
A resposta
Colaboradores do SuperUser Spiff, Hastur, jjlin. e Gustavo Giraldez tem a resposta para nós. Primeiro, Spiff:
!$ expands to the last word of your previous command. So you could do:
See the “HISTORY EXPANSION” section of the bash man page. There is a lot of flexibility there.
Seguido pela resposta do 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.
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.
Here are some more helpful words and commands.
Então a resposta de jjlin:
Ctrl+a to go to the beginning of the line, then Alt+d to delete the first word.
E nossa resposta final de 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.
Tem algo a acrescentar à explicação? Som desligado nos comentários. Quer ler mais respostas de outros usuários do Stack Exchange com experiência em tecnologia? Confira o tópico de discussão completo aqui.