Comment changer rapidement le premier mot d'une commande Bash?

Table des matières:

Comment changer rapidement le premier mot d'une commande Bash?
Comment changer rapidement le premier mot d'une commande Bash?

Vidéo: Comment changer rapidement le premier mot d'une commande Bash?

Vidéo: Comment changer rapidement le premier mot d'une commande Bash?
Vidéo: [TUTO] -changer les textes jaune du menu! - (Splashes) [HD] - YouTube 2024, Avril
Anonim
Si votre flux de travail contient de nombreuses actions répétitives, il est toujours utile de rechercher des moyens d'améliorer et de rationaliser votre flux de travail. L’article d’aujourd’hui, intitulé Q & R SuperUser, contient des suggestions utiles à l’intention d’un lecteur cherchant à améliorer son flux de travail.
Si votre flux de travail contient de nombreuses actions répétitives, il est toujours utile de rechercher des moyens d'améliorer et de rationaliser votre flux de travail. L’article d’aujourd’hui, intitulé Q & R SuperUser, contient des suggestions utiles à l’intention d’un lecteur cherchant à améliorer son flux de travail.

La séance de questions et réponses d’aujourd’hui nous est offerte par SuperUser, une sous-division de Stack Exchange, un groupe de sites Web de questions-réponses dirigé par la communauté.

Capture d'écran fournie par Matt Joyce (Flickr).

La question

Le lecteur superutilisateur cherche à savoir comment changer rapidement le premier mot d'une commande 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

2.) Bash
2.) Bash
Image
Image

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.

Y a-t-il un moyen plus rapide pour que pièce change le premier mot dans les commandes bash?

La réponse

Super contributeurs contributeurs Spiff, Hastur, jjlin. et Gustavo Giraldez ont la réponse pour nous. D'abord, Spiff:

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

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

Suivi de la réponse de 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.

Puis la réponse de jjlin:

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

Et notre réponse finale 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.

Avez-vous quelque chose à ajouter à l'explication? Sound off dans les commentaires. Voulez-vous lire plus de réponses d'autres utilisateurs de Stack Exchange doués en technologie? Découvrez le fil de discussion complet ici.

Conseillé: